GOOGLE CLOUD MESSAGING
FOR ANDROID
Bindu Priya Infosys Limited
Image Courtesy: http://developer.android.com/guide/google/gcm
The Challenge Mobile Phone Data in the cloud H OW TO KEEP DATA ON - - PowerPoint PPT Presentation
G OOGLE CLOUD MESSAGING FOR ANDROID Bindu Priya Infosys Limited Image Courtesy: http://developer.android.com/guide/google/gcm The Challenge Mobile Phone Data in the cloud H OW TO KEEP DATA ON YOUR DEVICE F RESH ? Polling Pushing Polling is
FOR ANDROID
Bindu Priya Infosys Limited
Image Courtesy: http://developer.android.com/guide/google/gcm
Data in the cloud Mobile Phone
DEVICE FRESH?
Any New Updates? No Any New Updates? No Device Application server
Polling Every 5 min can consume 10% of your battery AND.. Nobody appreciates the apps Nobody appreciates the apps which drains the battery life
Server Informs the phone once the new data is available
Device Application server
How many of you have heard about Cloud to Device Messaging Framework
Live Score C2DM Score Server Live Score App
Activation Email
the messages.
GCM Server
GCM Server
1.Registers Application with GCM and gets the API Key and Project ID
Phone Application Server
Project ID which will be used as GCM Sender ID.
select Services.
In the Terms of Service page, accept the
terms.
browser key should work .
import com.google.android.gcm.GCMRegistrar; @Override protected void onCreate(Bundle savedInstanceState) { if (GCMRegistrar.getRegistrationId(this).equals(“”)) { if (GCMRegistrar.getRegistrationId(this).equals(“”)) { GCMRegistrar.register(this, “12345678910”); }
import com.google.android.gcm.GCMBaseIntentService; public class GCMIntentService extends GCMBaseIntentService { @Override protected void onRegistered(Context ctx, String regId) { protected void onRegistered(Context ctx, String regId) { sendToLiveScoreServer(regId); } }
import com.google.android.gcm.server.*; Sender sender = new Sender(myApiKey); Message message = new Message.Builder().build(); MulticastResult result = sender.send(message, devices, MulticastResult result = sender.send(message, devices, 5);
<!-- App receives GCM messages. --> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <!-- GCM connects to Google Services. --> <uses-permission android:name="android.permission.INTERNET" /> <!-- GCM requires a Google account. --> <uses-permission android:name="android.permission.GET_ACCOUNTS" />
Live Score Server GCM Auth REG ID, API Key REG ID, API Key API Key Project ID Live Score App
GCM Default value is 4 weeks.
simple simple