Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCM 2.0 is not working in Android P

I'm implementing GCM in Android P.
But I cannot receive the broadcasting from GCM.
What's wrong in Android P?
By the way, working well in Android O.

    Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
    registrationIntent.setPackage("com.google.android.gsf");
    registrationIntent.putExtra("sender", sender_id);
    registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0));

public class GCMBroadcastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
        String messageType = gcm.getMessageType(intent);

        Log.e("GCM", "action=" + intent.getAction() + " registration_id="+intent.getStringExtra("registration_id"));
    }
}
like image 798
Jungsoo Nam Avatar asked Jul 27 '18 02:07

Jungsoo Nam


2 Answers

You must be using an older version of GCM.

Upgrade to GCM 11 or higher. (The latest is 15.0.1: com.google.android.gms:play-services-gcm:15.0.1), or even better, migrate to FCM. (GCM is now deprecated)

like image 112
OferR Avatar answered Sep 27 '22 19:09

OferR


the documentation states ...

As of April 10, 2018, Google has deprecated GCM. The GCM server and client APIs are deprecated and will be removed as soon as April 11, 2019. Migrate GCM apps to Firebase Cloud Messaging (FCM), which inherits the reliable and scalable GCM infrastructure, plus many new features. See the migration guide to learn more.

therefore, you might (sooner or later) have to migrate to FCM.

since recently, there's also Firebase In-App Messaging.

like image 33
Martin Zeitler Avatar answered Sep 27 '22 20:09

Martin Zeitler