我看到c2dm本身已经过时了。但是新的方法,Google Cloud Messaging似乎会使用com.google.android.c2dm.intent.RECEIVE作为操作来发送意图。
我的代码正在使用这个来获取注册密钥:
gcm = GoogleCloudMessaging.getInstance(getApplicationContext());
gcm.register(SENDER_ID);
事情正在正确地进行,但我在想是否有一些内容处于半废弃状态。
我看到c2dm本身已经过时了。但是新的方法,Google Cloud Messaging似乎会使用com.google.android.c2dm.intent.RECEIVE作为操作来发送意图。
我的代码正在使用这个来获取注册密钥:
gcm = GoogleCloudMessaging.getInstance(getApplicationContext());
gcm.register(SENDER_ID);
事情正在正确地进行,但我在想是否有一些内容处于半废弃状态。
是的,com.google.android.c2dm.intent.RECEIVE
仍在使用。当从GCM服务器接收包含GCM消息的广播时使用它。即使C2DM已经被弃用,但GCM仍然使用一些包含c2dm
的名称。
正如您在此清单示例中所看到的(摘自GCM指南),仍然有多个位置使用包含c2dm
或C2D
的名称:
<manifest package="com.example.gcm" ...>
...
<permission android:name="com.example.gcm.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />
<application ...>
<receiver
android:name=".GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.example.gcm" />
</intent-filter>
</receiver>
<service android:name=".GcmIntentService" />
</application>
com.google.android.c2dm.intent.RECEIVE
也被Firebase Cloud Messaging使用。
com.google.firebase:firebase-messaging:23.0.6
。 - Sujith S Manjavana <receiver
android:name=".GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.example.gcm" />
</intent-filter>
</receiver>
谷歌建议使用com.google.android.gms.gcm.GcmReceiver代替BroadcastReceiver,示例如下。
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.example.gcm" />
</intent-filter>
</receiver>