as I read, the function gcm.register() is deprecated. and I may use InstanceID.getToken() instead...
I use it as described here but every time I run the app, I get new RegID (Instance ID)..
here how I registered :
@Override
protected String doInBackground(Object[] voids) {
String msg = "";
if (gcm == null) {
gcm = GoogleCloudMessaging.getInstance(MyApp.getContext());
}
InstanceID instanceID = InstanceID.getInstance(context1);
EntryActivity. regid = null;
try {
EntryActivity.regid = instanceID.getToken(ConstantsGCM.senderID_ProjectID, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
Log.d("REG---", "========================>>>- regid= " + EntryActivity.regid);
} catch (IOException e) {
e.printStackTrace();
}
if (EntryActivity.regid != null)
try {
storeRegistrationId(context1, EntryActivity.regid);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
Log.d("REG---", "- " + msg + "regid= " + EntryActivity.regid);
return msg;
}
and then I sent "regid" to my server and save it to database, Until now everythig worked fine, but When I send a message to the server via GCM (gcm.send(...); ) and call the "from" field of the message (in the server side) I get a different regID, and every time I restart the app and send I get new regID (for each instace the regId changed).
How to use Instance ID as constant RegID, I read the documentations but did not undersatnd how!