Akhil
Akhil

Reputation: 303

How can we find device token in android emulator for Google Cloud Messaging

I am trying to implement google cloud messaging by using emulator. but in server side device token is needed. how can i get this token. how can i get the variable "device"

import com.google.android.gcm.server.*;

Sender sender = new Sender(myApiKey);
Message message = new Message.Builder().build();
MulticastResult result = sender.send(message, devices, 5);

Upvotes: 2

Views: 12779

Answers (3)

Chandramoli Mathur
Chandramoli Mathur

Reputation: 1

get device id by

import android.provider.Settings.Secure;
String android_id=Secure.getString(getContext().getContentResolver(),Secure.ANDROID_ID);

Upvotes: -1

Tofeeq Ahmad
Tofeeq Ahmad

Reputation: 11975

You can get the device ID like this

import android.provider.Settings.Secure;
String android_id=Secure.getString(getContext().getContentResolver(),Secure.ANDROID_ID);             

Upvotes: 3

Akhilesh Mani
Akhilesh Mani

Reputation: 3552

It register app with GCM. In return it will give an alpha numeric string which will sent to our server for notification. For getting GCM id for your project follow [developer page] : http://developer.android.com/guide/google/gcm/gs.html

 public String registerGCM(Context context)
 {
        String TAG = "GCM Already register";
        String SENDER_ID =<Your Gcm ID>;

        GCMRegistrar.checkDevice(context);
        GCMRegistrar.checkManifest(context);

        String gcmRegId = GCMRegistrar.getRegistrationId(context);
        System.out.println("GCM Reg id is ======>"+gcmRegId);

        if (gcmRegId.equals("")) 
        {
          GCMRegistrar.register(context, SENDER_ID);
          System.out.println("GCM Reg id is ======>blank");
          String gcmregID = GCMRegistrar.getRegistrationId(context);
          System.out.println("GCM Reg id is ======>"+gcmregID);
          return gcmregID;
        } 
        else 
        {
          Log.v(TAG, "Already registered");
        }
        return gcmRegId;
 }

Upvotes: 1

Related Questions