Registration confusion Android GCM

后端 未结 5 1034
忘掉有多难
忘掉有多难 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: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;
    }
    

提交回复
热议问题