0

I'm trying to follow this guide.

My GCM app receives messages via a class that extends WakefulBroadcastReciver. Upon receipt of a gcm message, I execute a GcmIntentService that processes the message via the following code . . .

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        // Explicitly specify that GcmIntentService will handle the intent.
        GlobalStuff.GCT = context.getApplicationContext();
                ComponentName comp = new ComponentName(context.getPackageName(),
                GcmIntentService.class.getName());
        // Start the service, keeping the device awake while it is launching.
        startWakefulService(context, (intent.setComponent(comp)));
        setResultCode(Activity.RESULT_OK);
    }
}

My AndroidManifest.xml defines the service as follows . . .

   <receiver
         android:name="com.deanblakely.myapp.GcmBroadcastReceiver"
         android:permission="com.google.android.c2dm.permission.SEND" >
         <intent-filter>
             <action android:name="com.google.android.c2dm.intent.RECEIVE" />
             <category android:name="com.deanblakely.myapp" />
         </intent-filter>
     </receiver>

The guide however only discusses migration of InstanceIDListenerService, GcmListenerService, and GcmPubSub. There is no discussion of what to do if I am using a GcmBroadcastReceiver. What should I do? Is there a better migration guide somewhere?

Dean Blakely
  • 3,535
  • 11
  • 51
  • 83
  • AFAIK, `GcmBroadcastReceiver ` is a class that has been deprecated even before FCM was announced. Possibly when GCM was still called C2DM? For receiving messages, the most latest class to receive messages in GCM was the `GcmListenerService` class, hence the counterpart for migration in FCM is `FirebaseMessagingService`. – AL. May 29 '18 at 02:27
  • AL, Thanks. Doesn't seem that long ago when this was current. Google can make breaking changes faster than I can code. I'm sure FCM will be depreciated by the time I finish. – Dean Blakely May 29 '18 at 16:20
  • Hey Dean. Pretty sure it's been [deprecated for more than 2yrs](https://stackoverflow.com/a/23520771/4625829) now. For FCM, I see it working for quite the foreseeable future. However, as tech advances, it would need to adjust. I would suggest looking into FCM v1 now if you can. – AL. May 29 '18 at 18:55
  • my GcmBroadcastReceiver ran in the background when my app was not running so I could receive messages when not active. I then created a notification. Does FirebaseMessagingService also run in the background? – Dean Blakely Jun 11 '18 at 22:26
  • I have an app running on FCM that works even when the app is on background. On my device, it even works when it is cleared from recent apps list. However, there are still some cases that when removed, it wouldn't work (see my [answer here](https://stackoverflow.com/a/39505298/4625829)). – AL. Jun 12 '18 at 05:40

0 Answers0