Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to get GCM registration token in Android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 548
    Comment on it

    GCM(Google Cloud Messaging) registration token is a kind of id given by the GCM connection server to user/client that allow user to receive messages. To get registration token first we have to generate a unique number, it can be created while configure your API project, now given as Project number in Google Developer Console.

    AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>() {
    
           @Override
           protected void onPreExecute() {
              super.onPreExecute();
                    
           }
    
           @Override
           protected String doInBackground(Void... params) {
    
               try {
                   InstanceID instanceID = InstanceID.getInstance(context);
                   token = instanceID.getToken(context.getResources().getString(R.string.gcm_defaultSenderId),
                                GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
    
                   } catch (Exception e) {
    
                        Log.d("TAG", "Failed to get token", e);
                   }
                    return token;
           }
    
           @Override
           protected void onPostExecute(String token) {
    
                Log.i("GCM Registration Token:", token);
           }
    };
    task.execute();

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: