Is com.google.android.c2dm.intent.REGISTRATION dep

2019-02-16 14:31发布

Short version: is the intent com.google.android.c2dm.intent.REGISTRATION still used at all or has it been completely deprecated by GCM?

Longer version: Google's gcm-demo-client declares this intent in its filter, however, if I follow the same procedure, I get a valid registration id when I call gcm.register() and then, my broadcast receiver receives an additional registration id because of the REGISTRATION filter, and this second registration id is bogus (I can't send any notification to it).

At this point, I'm considering removing the REGISTRATION filter (and keeping just RECEIVE) but I want to make sure I'm not missing something important in the protocol.

3条回答
混吃等死
2楼-- · 2019-02-16 15:02

Even for the latest GCM version (aka GCM 3) the official GCM documentation warns about the need of this permission for push support on old devices:

If you want to support pre-4.4 KitKat devices, add the following action to the intent filter declaration for the receiver: <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

查看更多
Rolldiameter
3楼-- · 2019-02-16 15:08

You are probably looking at an older version of the official Google demo. The current version doesn't use com.google.android.c2dm.intent.REGISTRATION, as you can see here:

    <receiver
        android:name=".GcmBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <!-- Receives the actual messages. -->
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="com.google.android.gcm.demo.app" />
        </intent-filter>
    </receiver>
查看更多
手持菜刀,她持情操
4楼-- · 2019-02-16 15:16

You risk not receiving registration IDs for a small percentage of your users.

https://blog.pushbullet.com/2014/02/12/keeping-google-cloud-messaging-for-android-working-reliably-techincal-post/

Lesson #2: Be ready for register to repeatedly fail on some devices even though a working registration ID is created.

This tip is rather bizarre and may no longer be relevant but I have no way of confirming if the bug in GCM has been fixed so here it is.

The bug goes like this: no matter how many times you call register, it will always fail and throw an exception on some devices. Even though register is throwing an exception, a working registration ID is being created but not returned. To get this registration ID, add this permission to your GCM BroadcastReceiver’s IntentFilter:

<action android:name="com.google.android.c2dm.intent.REGISTRATION" />

Gotta love GCM. =)

查看更多
登录 后发表回答