Search code examples
androidpush-notificationgoogle-cloud-messagingandroid-c2dmandroid-9.0-pie

com.google.android.c2dm.intent.RECEIVE android 9 (sdk 28) doesn't work


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.


Solution

  • You can use

    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(mContext);
    String token = gcm.register(SENDER_ID);