Registration confusion Android GCM

后端 未结 5 999
忘掉有多难
忘掉有多难 2021-01-02 07:10

I am trying to migrate to GCM in Android, C2DM now being deprecated. The registration process described here is different from registration describ

相关标签:
5条回答
  • 2021-01-02 07:22

    They are actually the same thing. The second one encapsulates the first one in a static method and registers a broadcast receiver. You can attach the source to the gcm.jar and see for yourself. You can find source code in ~/android-sdks/extras/google/gcm/gcm-client/gcm-src.jar

    0 讨论(0)
  • 2021-01-02 07:23

    The Thing I like most in GCM is the RegID we will get from GCM server,it is not only an ID its an Address of this application on this Device. So this time you don't need to send a device Id to server along with your Registration Id as per was in C2DM.

    In C2DM every time you request a registration id you will get a new ID.

    But in GCM RegId generated by using your application package along with some device id so if you will request for Registration Id again and again you will receive the same RegId.

    And if you uninstall an application and will install it again still GCM server will give you the same Registration Id.

    So one Registraion Id will do no need of any Device Id to send to server.

    0 讨论(0)
  • 2021-01-02 07:26

    I have been successful at migrating from C2DM to GCM. I have also documented how to implement GCM at http://android.amolgupta.in/2012/07/google-cloud-messaging-gcm-tutorial.html

    0 讨论(0)
  • 2021-01-02 07:30

    GCMRegistrar is just a helper that does the leg work described in the first page.

    You can see the class here. android-sdk\extras\google\gcm\gcmclient\src\com\google\android\gcm.

    0 讨论(0)
  • 2021-01-02 07:43

    I've successfully migrated my C2DM project to GCM. Tested, it works fine. The only changes were:

    • in the Android app - change the value of sender upon registration
    • on the server side - change the auth header and the URL

    That was it, as far as the interaction with Google goes. There were more some changes dictated by the app's logic:

    • in the Android app, the registration ID was cached in its preferences. Upon upgrade, I remove reg ID from the preferences to force re-registration, this time with GCM.
    • the logic of passing the reg ID to the server got an extra boolean parameter - if this is a C2DM or GCM reg ID
    • the logic of sending messages became conditional upon the said parameter.

    Throwing out the C2DM logic completely out of the server would be unwise - not everyone upgrades their Android apps. The old, C2DM-enabled versions will be out in the wild for some time. And Google pledged to keep C2DM running in the short term. So message sending is conditional - depending on reg ID type, it sends either to GCM or to C2DM.

    EDIT re: conditional logic:

    if($RegID_Is_GCM)
    {
        $Auth = GCM_Auth();
        $URL = $GCM_URL;
    }
    else
    {
        $Auth = C2DM_AUTH();
        $URL = $C2DM_URL;
    }
    
    0 讨论(0)
提交回复
热议问题