2

I'm having issues with the new Android-SDK 28 from Google. (Android Pie)

I'm trying to send a c2dm cloud message (push notification), everything works fine on API level lower or equal to 27 (tested with real phones and simulator), but on API level 28, it fails - the onReceive is not called on a subclass of BroadcastReceiver that handles the broadcast.

I've been reading everything I could find on this issue, but to no avail, any useful hints are welcome.

EDIT2: uploaded example project: https://ufile.io/qb3uu You need to edit the SENDER_ID in GCMIntentService with your key. As far as I know, the only way to get a GCM key is to have one already as Google disabled the access to a working console a while ago.

StefanS
  • 1,089
  • 1
  • 11
  • 38
  • Is this broadcast receiver declared in manifest or registered in runtime? – Pawel Aug 15 '18 at 13:07
  • It is declared in the manifest, but i can re-register it at runtime, just a sec to test it. `GCMBroadcastReceiver receiver = new GCMBroadcastReceiver(); // IntentFilter filter = new IntentFilter(); // filter.addAction("com.google.android.c2dm.intent.RECEIVE"); // filter.addAction("com.google.android.c2dm.intent.REGISTRATION"); // filter.addCategory("com.myapp"); // registerReceiver(receiver, filter, "com.google.android.c2dm.permission.SEND", null);` Is this ok? @Pawel – StefanS Aug 15 '18 at 13:07
  • GCM has already been deprecated, you should use FCM – Saurabh Aug 15 '18 at 13:09
  • @Saurabh I'm fixing an abandoned project from my company, and the server cannot be updated until December. This is why we need to fix android 9 first, then fix the server, then give an update with FCM. Currently this is the issue i need to resolve. – StefanS Aug 15 '18 at 13:10
  • @Pawel, tested with the above code - this is set on `onCreate()` but with no luck. – StefanS Aug 15 '18 at 13:13
  • Also tested the BroadcastReceiver with adb like so : `./adb shell am broadcast -c com.myapp -a com.google.android.c2dm.intent.RECEIVE -e data "SomeData"` (while disabling the SEND permission) and it works on Android 9 - so the mechanism is not broken, seems like the cloud messages are just not delivered to the Android Pie devices. I'm stuck. Help! – StefanS Aug 15 '18 at 13:22
  • Updating to `FCM` on server is not a big deal, Just you need to update endpoint **URL** to https://fcm.googleapis.com/fcm/send – Khaled Lela Aug 16 '18 at 06:29
  • @KhaledLela, we already did that, we already have the fix on both client and server side, we just can't send the update just yet, politics. – StefanS Aug 16 '18 at 06:49

1 Answers1

2

You can use

GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(mContext);
String token = gcm.register(SENDER_ID);
George
  • 116
  • 3