com.google.android.c2dm.intent.RECEIVE仍在使用吗?

17

我看到c2dm本身已经过时了。但是新的方法,Google Cloud Messaging似乎会使用com.google.android.c2dm.intent.RECEIVE作为操作来发送意图。

我的代码正在使用这个来获取注册密钥:

gcm = GoogleCloudMessaging.getInstance(getApplicationContext());
gcm.register(SENDER_ID);

事情正在正确地进行,但我在想是否有一些内容处于半废弃状态。

3个回答

18

是的,com.google.android.c2dm.intent.RECEIVE仍在使用。当从GCM服务器接收包含GCM消息的广播时使用它。即使C2DM已经被弃用,但GCM仍然使用一些包含c2dm的名称。

正如您在此清单示例中所看到的(摘自GCM指南),仍然有多个位置使用包含c2dmC2D的名称:

<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>


2
好的,很酷,我也有那些东西。当你在谷歌搜索时,看到一个大红色段落告诉你它已被弃用,这真的很令人困惑。 - Carlos
应该选择什么类别?是“com.example.gcm”还是我应该放置我的应用程序包名称? - Gavriel

5

com.google.android.c2dm.intent.RECEIVE也被Firebase Cloud Messaging使用。


1
这还有用吗?我正在使用com.google.firebase:firebase-messaging:23.0.6 - Sujith S Manjavana

2
关于接收器声明
    <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>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接