How to rename or move GCMIntentService

2019-05-28 21:16发布

问题:

I would like to put the GCMIntentService in a directory other than my package root.

The GCM documentation states that

      By default, it must be named .GCMIntentService, unless the
      application uses a custom BroadcastReceiver that redefines its name.

My question is - how do I create this "custom BroadcastReceiver" thay talk about?

回答1:

Try this -- Rename or change package of GCMIntentService class



回答2:

The basic docs have you add the following to your manifest:

<receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" >
  <intent-filter>
    <action android:name="com.google.android.c2dm.intent.RECEIVE" />
    <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
    <category android:name="my_app_package" />
  </intent-filter>
</receiver>

This points to a GCM-supplied BroadcastReceiver that will route events to your .GCMIntentService. If you wish to have your service reside in some other package, you will need to supply your own BroadcastReceiver. This may be as simple as creating one that subclasses GCMBroadcastReceiver and overrides getGCMIntentServiceClassName() to return the fully-qualified class name of the service to use.