Android GCM registration / device id for push notification changes every time
I used this code to get the gcm registration id. ( Formerly )
// Make sure the device has the proper dependencies.
GCMRegistrar.checkDevice(this);
// Make sure the manifest was properly set - comment out this line
// while developing the app, then uncomment it when it ready.
GCMRegistrar.checkManifest(this);
// registerReceiver(mHandleMessageReceiver, new IntentFilter(
// CommonUtilities.DISPLAY_MESSAGE_ACTION));
// Get GCM registration id
final String regId = GCMRegistrar.getRegistrationId(this);
// Check if regid already presents
if (regId.equals("")) {
// Registration is not present, register now with GCM
GCMRegistrar.register(this, CommonUtilities.SENDER_ID);
} else {
AppSharedPreferences.saveDeviceIDPreference(ctx, regId);
// Device is already registered on GCM
if (GCMRegistrar.isRegisteredOnServer(this)) {
// Skips registration.
// Toast.makeText(getApplicationContext(), "Already registered with GCM", Toast.LENGTH_LONG).show();
} else {
// Try to register again, but not in the UI thread.
// It also necessary to cancel the thread onDestroy(),
// hence the use of AsyncTask instead of a raw thread.
final Context context = this;
mRegisterTask = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
// Register on our server
// On server creates a new user
ServerUtilities.register(context, regId);
return null;
}
@Override
protected void onPostExecute(Void result) {
mRegisterTask = null;
}
};
mRegisterTask.execute(null, null, null);
}
}
But, shockingly, he seems to change each time the performance, . Please let me know the possible reason for this. for the same device and same application
EDITED
modified GCM to newer version
gcm = GoogleCloudMessaging.getInstance(this);
new RegisterBackground().execute();
Further on this tutorial .
But, still the same behavior, that is, getting a new reg id with each installation.
+3
source to share
No one has answered this question yet
Check out similar questions: