Android GCM registration / device id for push notification is getting changed everytime -
i used code gcm registration id. (earlier)
// make sure device has proper dependencies. gcmregistrar.checkdevice(this); // make sure manifest set - comment out line // while developing app, uncomment when it's ready. gcmregistrar.checkmanifest(this); // registerreceiver(mhandlemessagereceiver, new intentfilter( // commonutilities.display_message_action)); // gcm registration id final string regid = gcmregistrar.getregistrationid(this); // check if regid presents if (regid.equals("")) { // registration not present, register gcm gcmregistrar.register(this, commonutilities.sender_id); } else { appsharedpreferences.savedeviceidpreference(ctx, regid); // device registered on gcm if (gcmregistrar.isregisteredonserver(this)) { // skips registration. // toast.maketext(getapplicationcontext(), "already registered gcm", toast.length_long).show(); } else { // try register again, not in ui thread. // it's necessary cancel thread ondestroy(), // hence use of asynctask instead of 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 new user serverutilities.register(context, regid); return null; } @override protected void onpostexecute(void result) { mregistertask = null; } }; mregistertask.execute(null, null, null); } }
but, shockingly, seems change everytime on execution, for same device , same application
. please let me know possible reason of that.
edited
modified gcm newer version
gcm = googlecloudmessaging.getinstance(this); new registerbackground().execute();
followed this tutorial.
but, still same behaviour, i.e, getting new reg id on every install.
Comments
Post a Comment