Android GCMBasEventService回调仅在根包中

Android GCMBasEventService回调仅在根包中,android,push-notification,google-cloud-messaging,intentservice,Android,Push Notification,Google Cloud Messaging,Intentservice,我在我的应用程序中实现了GCM,我遇到了一个奇怪的问题。 当我的GCMBaseIntentService的重写IntentService位于我的根包中时,它工作正常。我在清单中用.mygcminentservice引用它。 根包应该是com.example.rootpackage 当我将意图服务移动到另一个包时,例如com.example.rootpackage.service从未调用意图服务。此时,我会将清单更新为指向com.example.rootpackage.service.mygcmi

我在我的应用程序中实现了GCM,我遇到了一个奇怪的问题。 当我的
GCMBaseIntentService
的重写
IntentService
位于我的根包中时,它工作正常。我在清单中用
.mygcminentservice
引用它。 根包应该是
com.example.rootpackage

当我将意图服务移动到另一个包时,例如
com.example.rootpackage.service
从未调用意图服务。此时,我会将清单更新为指向
com.example.rootpackage.service.mygcminentservice
,无骰子


我是否在谷歌的文档中遗漏了一些关于定位它的信息,或者这就是它的工作原理?

是的,它应该在根包中:

GCMBroadcastReceiver(由GCM库提供)将调用此意向服务,如下一步所示。它必须是com.google.android.gcm.GCMBaseIntentService的子类,必须包含公共构造函数,并且应命名为my_app_package.gcminentService(除非您使用gcmbroadcasreceiver的子类覆盖用于命名服务的方法)

(引自)

编辑:

如文档所述,如果使用覆盖
getDefaultIntentServiceClassName
GCMBroadcastReceiver
子类,则可以对其进行更改:

public class GCMBroadcastReceiver extends BroadcastReceiver {

    private static final String TAG = "GCMBroadcastReceiver";
    private static boolean mReceiverSet = false;

    @Override
    public final void onReceive(Context context, Intent intent) {
        Log.v(TAG, "onReceive: " + intent.getAction());
        // do a one-time check if app is using a custom GCMBroadcastReceiver
        if (!mReceiverSet) {
            mReceiverSet = true;
            String myClass = getClass().getName();
            if (!myClass.equals(GCMBroadcastReceiver.class.getName())) {
                GCMRegistrar.setRetryReceiverClassName(myClass);
            }
        }
        String className = getGCMIntentServiceClassName(context);
        Log.v(TAG, "GCM IntentService class: " + className);
        // Delegates to the application-specific intent service.
        GCMBaseIntentService.runIntentInService(context, intent, className);
        setResult(Activity.RESULT_OK, null /* data */, null /* extra */);
    }

    /**
     * Gets the class name of the intent service that will handle GCM messages.
     */
    protected String getGCMIntentServiceClassName(Context context) {
        return getDefaultIntentServiceClassName(context);
    }

    /**
     * Gets the default class name of the intent service that will handle GCM
     * messages.
     */
    static final String getDefaultIntentServiceClassName(Context context) {
        String className = context.getPackageName() +
                DEFAULT_INTENT_SERVICE_CLASS_NAME;
        return className;
    }
}

感谢您的详细回复!