1

I have an app with a Login functionality and also auto Login, and before login screen, a Splash Screen Activity is displayed. Inside Splash Screen activity I want to check if the user has just updated the app from the Google play to a newer version, and if so, to always show him the Login screen. So my question is, how to check if current version app is different from the last version? I tried solutions found in this topic: Detect if new install or updated version (Android app)

But in this function

public static boolean isInstallFromUpdate(Context context) {
    try {
        long firstInstallTime = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).firstInstallTime;
        long lastUpdateTime = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).lastUpdateTime;
        return firstInstallTime != lastUpdateTime;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        return false;
    }
}

This line is always true: firstInstallTime != lastUpdateTime;, but after an update, if I close the app and then reopen it, this line should be false. If you have any suggestions or need more details, please let me know! Thanks

Razvan22
  • 153
  • 2
  • 12

2 Answers2

0

I think a simple solution is if you have an admin panel of mobile app for data calling then you have to store version detail latest and these data related API call into your app so easily detect if you have to change the version in admin panel then show a dialog of update app and redirect to play store...

This is my personal opinion because I have used this kind of method .....

axar
  • 539
  • 2
  • 17
0

You can simply set a SharedPreference, if you open the app after an update. After you closed the app and reopened it, you should check for your isInstallFromUpdate(...) and the just set SharedPreference

Camillo
  • 153
  • 1
  • 9