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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25207960/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:13:06  来源:igfitidea点击:

Is com.google.android.c2dm.intent.RECEIVE still in use?

androidandroid-intentpush-notificationgoogle-cloud-messaging

提问by Carlos

I've seen that c2dm itself is deprecated. But the new method, Google Cloud Messaging, seems to send intents with com.google.android.c2dm.intent.RECEIVEas the action.

我已经看到 c2dm 本身已被弃用。但是新方法 Google Cloud Messaging 似乎以com.google.android.c2dm.intent.RECEIVE作为操作发送意图。

My code is using this to get the registration key:

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

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

Things are arriving correctly, but I'm wondering if I've left something in a half-deprecated state.

事情正确到达,但我想知道我是否已经将某些东西置于半弃用状态。

回答by Eran

Yes, com.google.android.c2dm.intent.RECEIVEis still in use. It is used when receiving a broadcast from GCM server that contains a GCM message. Even though C2DM is long deprecated, GCM still uses some names that contain c2dm.

是的,com.google.android.c2dm.intent.RECEIVE还在使用中。它用于接收来自 GCM 服务器的包含 GCM 消息的广播。尽管 C2DM 早已弃用,但 GCM 仍然使用一些包含c2dm.

As you can see in this manifest sample (taken from the GCM guide), there are multiple places that still use names containing c2dmor C2D:

正如您在此清单示例中看到的(取自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>

回答by Zephyr

As for the Receiver declaration

至于接收方声明

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

Google suggested to replace BroadcastReceiver with the com.google.android.gms.gcm.GcmReceiver, just like below.

Google 建议将 BroadcastReceiver 替换为 com.google.android.gms.gcm.GcmReceiver,如下所示。

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

回答by hari

the com.google.android.c2dm.intent.RECEIVE also used by the firebase cloud messaging

firebase 云消息传递也使用的 com.google.android.c2dm.intent.RECEIVE