Register GCM from a library project

天大地大妈咪最大 提交于 2019-11-27 14:32:20
Eran

Here's what you have to do :

Write a class (in your library project) that overrides GCMBroadcastReceiver :

package com.test.pushlibrary;

import android.content.Context;

import com.google.android.gcm.GCMBroadcastReceiver;


public class PushLibraryBroadcastReceiver extends GCMBroadcastReceiver
{
    /**
     * Gets the class name of the intent service that will handle GCM messages.
     */
    @Override
    protected String getGCMIntentServiceClassName(Context context) {
        return "com.test.pushlibrary.GCMIntentService";
    }
}

Change your manifest to refer to the new receiver :

    <receiver
        android:name="com.test.pushlibrary.PushLibraryBroadcastReceiver"
        ...

The reason that your original code didn't work is that the default implementation of getGCMIntentServiceClassName assumes that the intent service class is located in the package of the application, so it's expecting com.example.pushtest.GCMIntentService instead of com.test.pushlibrary.GCMIntentService.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!