Migration from C2DM to GCM

不问归期 提交于 2019-12-13 16:22:29

问题


I reading this, but I don't understand what I must do. Now my application doing registration in c2dm by this code:

String pushId =  C2DMessaging.getRegistrationId(this);
if(pushId == "")
{
    C2DMessaging.register(this, "email@gmail.com");
}

What I must change in this code to do migration from c2dm to gcm?


回答1:


First, go through the Getting Started steps. Once you created an API project, you will receive a 'Project ID', as mentioned #4 item on that document:

Take note of the value after #project: (4815162342 in this example). This is your project ID, and it will be used later on as the GCM sender ID.

So you just need to change your code to:

C2DMessaging.register(this, "4815162342");

The senderID must be a string number.

I am using the example from the 'Getting Started' guide, you should replace the sender ID with your own Project ID.

Finally, go through the GCM Architectural Overview, as you need to make some changes to the server for all of these to work.




回答2:


What you need to change is basically the email address. You need to send instead the API Key which you received in Google APIs Console page.




回答3:


In GCM to get rid from Qutota google removed the signup an activation of an email for using Google Cloud Service.

When you go to Google Developer Console Here and click on create a new project that will give you a new project id that will be present in URL.

The PROJECT ID here will work like a user name and one more thing, this time Google is providing a jar gcm.jar that you need to add in your project classpath using build path to make GCM work .

this jar contains a class named GCMRegistrar having predefined function register() so you just need to add this code and forget

final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
  GCMRegistrar.register(this, SENDER_ID);
} else {
  Log.v(TAG, "Already registered");
}

In C2DM SENDER_ID : Activated Gmail ID.

In GCM SENDER_ID : PROJECT ID in url .



来源:https://stackoverflow.com/questions/11326065/migration-from-c2dm-to-gcm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!