android - InstanceId#getId() doesn't return stable Id -
according docs instanceid:
provides unique identifier each app instance
and instance id stable may become invalid, if:
- app deletes instance id
- device factory reset
- user uninstalls app
- user clears app data
however testing, appears following call returns different id if app has been swiped recents.
instanceid.getinstance(context).getid(); is bug in google play services or using plain wrong?
2 tymm answer: client library instance id code:
boolean needrefreshtoken() { string appversion = ssharedpreferenceshelper.get("appversion"); if (appversion == null) { return true; } if (!appversion.equals(scurrentappversion)) { return true; } string lasttokenacquiringtime = ssharedpreferenceshelper.get("lasttoken"); if (lasttokenacquiringtime == null) { return true; } long l = long.parselong(lasttokenacquiringtime); if (system.currenttimemillis() / 1000 - l <= 3600*24*7) { return false; } return true; } about direct question: each instance id backed keypair stored in app preferences named "com.google.android.gms.appid";
instanceid.getinstance(context).getid() returns sha-1 digest of public key in base64 format. try investigate why it's impossible restore keypair preferences ;)
error here inside library code (com.google.android.gms.iid.zzd.class):
keypair zzdj(string subtype) { string string2 = this.get(subtype, "|p|"); string string3 = this.get(subtype, "|k|"); ... should be:
keypair zzdj(string subtype) { string string2 = this.get(subtype + "|p|"); string string3 = this.get(subtype + "|k|"); ... so, please iid registration token (it's first part till colon) after gettoken(...) command. because getid() initializes "promise" keypair used next server request in case if app forcibly stopped task bar causes complete unload static variables.
here hot fix (please put before call getid()):
public void fixpreferenceskeysid() { sharedpreferences sh = getsharedpreferences("com.google.android.gms.appid", mode_private); string privk = sh.getstring("|k|", null); if (privk != null) { sh.edit().remove("|k|").putstring("|s||k|", privk).commit(); } string pubk = sh.getstring("|p|", null); if (pubk != null) { sh.edit().remove("|p|").putstring("|s||p|", pubk).commit(); } }
Comments
Post a Comment