【问题标题】:Is com.google.android.c2dm.intent.RECEIVE still in use?com.google.android.c2dm.intent.RECEIVE 还在使用吗?
【发布时间】:2014-08-08 16:25:21
【问题描述】:

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

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

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

事情进展顺利,但我想知道我是否让某些东西处于半弃用状态。

【问题讨论】:

    标签: android android-intent push-notification google-cloud-messaging


    【解决方案1】:

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

    正如您在此清单示例中所见(取自 GCM guide),有多个地方仍在使用包含 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>
    

    【讨论】:

    • 好吧,我也有这些。当你用谷歌搜索它时会感到困惑,并且有一个大的红色段落告诉你它已被弃用。
    • 类别应该是什么? “com.example.gcm”还是我应该把我的应用程序的包名放在那里?
    【解决方案2】:

    关于 Receiver 声明

        <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 建议将 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>
    

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 2011-06-27
        • 2017-09-12
        • 2018-10-27
        • 1970-01-01
        • 2018-02-03
        • 1970-01-01
        • 1970-01-01
        • 2011-04-11
        • 2011-02-28
        相关资源
        最近更新 更多