Detect if new install or updated version (Android app)

前端 未结 8 1031
-上瘾入骨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:52

    You can get the version code and version name using below code snippet

    String versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
    
    int versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
    

    Now you can check for the latest version and restrict as per your requirement.

    0 讨论(0)
  • 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
    0 讨论(0)
提交回复
热议问题