Detect if new install or updated version (Android app)

前端 未结 8 1103
-上瘾入骨i
-上瘾入骨i 2020-12-24 06:41

I have an app on the Play Store. I want to put a requirement that if users want to use a certain part of the app, they have to invite a friend before being able to do so. Bu

8条回答
  •  鱼传尺愫
    2020-12-24 06:56

    My solution is use SahredPreference

    private int getFirstTimeRun() {
        SharedPreferences sp = getSharedPreferences("MYAPP", 0);
        int result, currentVersionCode = BuildConfig.VERSION_CODE;
        int lastVersionCode = sp.getInt("FIRSTTIMERUN", -1);
        if (lastVersionCode == -1) result = 0; else
            result = (lastVersionCode == currentVersionCode) ? 1 : 2;
        sp.edit().putInt("FIRSTTIMERUN", currentVersionCode).apply();
        return result;
    }
    

    return 3 posibles values:

    • 0: The APP is First Install
    • 1: The APP run once time
    • 2: The APP is Updated

提交回复
热议问题