Monday, February 16, 2015

How to fetch registration ID for GCM in android

To send or get messages in Android, your application firstly needs to get an enrolment/registration ID. The enrolment/registration  ID which recognizes the gadget and application, furthermore figures out which third gathering application servers are permitted to send messages to this application case.

To get an enrolment / registration ID, you must supply one or more sender IDs.



This method will fetch registration ID from google.

String regId ="",msg ="";

public void getRegisterationID() {

 new AsyncTask() {
  @Override
  protected Object doInBackground(Object... params) {
   // TODO Auto-generated method stub
   String msg = "";
   try {
    if (gcm == null) {
     gcm = GoogleCloudMessaging.getInstance(Login.this);
    }
    regId = gcm.register(CommonUtilities.SENDER_ID);
    Log.d("in async task", regId);

        // try
    msg = "Device registered, registration ID=" + regId;
 
   } catch (IOException ex) {
    msg = "Error :" + ex.getMessage();

   }
   return msg;
  }
 }.execute(null, null, null);

}

2 comments:

Don't lose faith when you see others receive answers to their prayers

An elephant and a dog became pregnant at same time. Three months down the line the dog gave birth to six puppies. Six months later the dog...

 

G-Expo Template by Ipietoon Cute Blog Design