2012年8月25日 星期六

Migrating Your Apps

Migrating Your Apps


This section describes how to move existing C2DM apps to GCM.

Client changes

Migration is simple! The only change required in the application is replacing the email account passed in the sender parameter of the registration intent with the project ID generated when signing up for the new service. For example:
Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
// sets the app name in the intent
registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0));
registrationIntent.putExtra("sender", senderID);
startService(registrationIntent);
After receiving a response from GCM, the registration ID obtained must be sent to the application server. When doing this, the application should indicate that it is sending a GCM registration ID so that the server can distinguish it from existing C2DM registrations.
從GCM接收到響應獲得註冊ID必須被發送到應用程序服務器在這樣做時,應用程序應該表明它已被發送一個GCM註冊ID,這樣服務器可以區分從現有的C2DM註冊

Server changes

When the application server receives a GCM registration ID, it should store it and mark it as such.
Sending messages to GCM devices requires a few changes:
  • The request should be sent to a new endpoint: https://android.googleapis.com/gcm/send.
  • The Authorization header of the request should contain the API key generated during sign up. This key replaces the deprecated ClientLogin Auth token.
For example:
Content-Type:application/json
Authorization:key=AIzaSyB-1uEai2WiUapxCs2Q0GZYzPu7Udno5aA

{
  "registration_id" : "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...",
  "data" : {
    "Team" : "Portugal",
    "Score" : "3",
    "Player" : "Varela",
  },
}
For a detailed discussion of this topic and more examples, see the Architectural Overview.
Eventually, once enough users of your application have migrated to the new service, you might want to take advantage of the new JSON-formatted requests that give access to the full set of features provided by GCM.

沒有留言:

張貼留言