androidpush-notificationurbanairship.comgcmlistenerservice

An exception occurred when starting service: com.google.android.c2dm.intent.REGISTER


I am using Urban Airship for push notifications. The app compiles but I am not receiving push notifications and I see this in the Android Studio log:

`D/Example - UALib: Starting GCM
V/Example - UALib: Version code changed to 10. GCM re-registration required.
D/Example - UALib: GCMRegistrar startService
E/Example - UALib: An exception occurred when starting service: com.google.android.c2dm.intent.REGISTER
                      java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.google.android.c2dm.intent.REGISTER (has extras) }
                          at android.app.ContextImpl.validateServiceIntent(ContextImpl.java:1813)
                          at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1842)
                          at android.app.ContextImpl.startService(ContextImpl.java:1826)
                          at android.content.ContextWrapper.startService(ContextWrapper.java:516)
                          at com.urbanairship.push.GCMRegistrar.startService(GCMRegistrar.java:401)
                          at com.urbanairship.push.GCMRegistrar.register(GCMRegistrar.java:126)
                          at com.urbanairship.push.PushService.startPushService(PushService.java:306)
                          at com.urbanairship.push.PushService.onHandleIntent(PushService.java:136)
                          at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
                          at android.os.Handler.dispatchMessage(Handler.java:102)
                          at android.os.Looper.loop(Looper.java:135)
                          at android.os.HandlerThread.run(HandlerThread.java:61)`

In my AndroidManifest.xml file, I have this:

`<receiver android:name="com.urbanairship.push.GCMPushReceiver" 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" />
        <!-- MODIFICATION REQUIRED - Use your package name as the category -->
        <category android:name="com.example" />
    </intent-filter>
    <!--  REQUIRED for detecting when the application is upgraded so it can request a new GCM ID -->
    <intent-filter>
        <action android:name="android.intent.action.PACKAGE_REPLACED" />
        <data android:scheme="com.example"/>
    </intent-filter>
</receiver>
<service android:name="com.urbanairship.push.PushService" android:label="Push Notification Service"/>`

In my build.grandle file, I am using "targetSdkVersion 23" for API Level 23, for Android 6.0; and "minSdkVersion 16" for API Level 16, which is for Android 4.1.x if I remember correctly.

My Urban Airship configuration is correct, as confirmed by the Urban Airship Support Team. This issue is isolated to my app's registration with GCM for push services. This does not happen via Urban Airship, but rather between the app and GCM itself. Once a valid registration id has been received from GCM by my app, that id is passed along to Urban Airship.

I know GCM is deprecated and at https://developers.google.com/cloud-messaging/ they say: "Firebase Cloud Messaging (FCM) is the new version of GCM". My question is, can I still use GCM with API Level 23, or do I definitely must upgrade from GCM to FCM for the push notifications to work? I even tried this but I have not been able to register my app with GCM for push services:

`
Context context = getApplicationContext();
NotificationManager notificationManager = (NotificationManager) context
    .getSystemService(Context.NOTIFICATION_SERVICE);
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
try {
    gcm.register();
} catch (IOException e) {
    e.printStackTrace();
}`

Solution

  • The crash is due to an implicit intent to start a service that use to be required in older integration with GCM. I believe Google stopped allowing implicit intents for services in Android Lollipop, so once you bumped your target SDK version it probably started crashing because the app is no longer running in compatibility mode.

    I would recommend updating to the latest version of Urban Airship. A lot has changed since 3.x, so it could be a rather large migration. The first step is to remove the manifest entries and the jar, then follow Android Platform guide to integrate the latest version.