Jun*_*Nam 5 android push google-cloud-messaging
我正在Android P中实现GCM。
但是我无法从GCM接收广播。
Android P有什么问题?
顺便说一句,在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"));
}
}
Run Code Online (Sandbox Code Playgroud)
您必须使用旧版本的 GCM。
升级到 GCM 11 或更高版本。(最新的是 15.0.1:com.google.android.gms:play-services-gcm:15.0.1),或者更好的是,迁移到 FCM。(GCM 现已弃用)
| 归档时间: |
|
| 查看次数: |
1885 次 |
| 最近记录: |