android - Device Token returns null for the first time -
i used next code getting device token in android device. i'm getting null value first attempt.
gcmregistrar.checkdevice(this); gcmregistrar.checkmanifest(this); string regid = gcmregistrar.getregistrationid(this); if (regid.equals("")) { gcmregistrar.register(this, utilsgcm.gcmsenderid); }
here gcm class used
public class gcmintentservice extends gcmbaseintentservice { public gcmintentservice() { super(utilsgcm.gcmsenderid); } @override protected void onerror(context context, string regid) { log.e("", "error registration id : " + regid); } @override protected void onmessage(context context, intent intent) { handlemessage(context, intent); } @override protected void onregistered(context context, string regid) { system.out.println("on registered" + regid); utilsgcm.registrationid = regid; handleregistration(context, regid); } @override protected void onunregistered(context arg0, string arg1) { } }
i dunno weather gona work out or not anyway give try....and allow me know in gcm class check weather nowadays or not if not place there
private void handleregistration(context context, string regid) { // todo auto-generated method stub utils.registrationid = regid; savepreferences("pushnot",regid); log.e("", "registration id : "+regid); //senddeviceidfuction(context,utilsgcm.registrationid); } private void savepreferences(string key, string value) { // todo auto-generated method stub sharedpreferences sharedpreferences = getsharedpreferences("myprefs", mode_private); sharedpreferences.editor editor = sharedpreferences.edit(); editor.putstring(key, value); editor.commit(); }
here save regid after registration in app preference seek retrieve preference value instead of taking string regid.
android push-notification google-cloud-messaging
No comments:
Post a Comment