InstanceId # getId () does not return a stable identifier

According to the docs instance of InstanceId:

provides a unique identifier for each application instance

and that the instance identifier is stable, but may become invalid if:

  • Application removes instance id
  • Factory reset device
  • User uninstalls application
  • The user deletes the application data.

However, from my testing, it seems that the next call returns a different identifier, even if the application was only pushed out of iteration.

InstanceID.getInstance(context).getID();

Is this a bug on Google Play services, or am I using it incorrectly?

+4
source share
2 answers

2 tymm answer: :

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;
    }

: , "com.google.android.gms.appid";
InstanceID.getInstance(context).getID() SHA-1 Base64. , KeyPair ;)
(com.google.android.gms.iid.zzd.class):

    KeyPair zzdj(String subtype) {
        String string2 = this.get(subtype, "|P|");
        String string3 = this.get(subtype, "|K|");
...

:

KeyPair zzdj(String subtype) {
    String string2 = this.get(subtype + "|P|");
    String string3 = this.get(subtype + "|K|");
...

, , ( ) getToken (...). getID() "" KeyPair, , , .
(, 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();            
    }
}
+2

, , , - ( ,...).

, GCM , , .

0

All Articles