How to detect Android App has been upgraded from version x to y?

EV221

I have a problem with my android app for own educational reason.

Is there a ready solution to detect that the app has now been updated from version x to y? Because I want to migrate some data once only if the app was installed in a special version before.

Thanks.

Md. Sajedul Karim

Here is a simple way that can solve your problem. In your code you can easily get the app versionCode and versionName. In your home activity you check isAppUpdated(). if current APP VERSION_NAME is not matched with stored VERSION_NAME then app is updated.

Here is sample code:

Save VersionName in preferences:

public static void saveVersionNameAndCode(Context context){
        try{
            PackageInfo packageInfo = context.getPackageManager()
                    .getPackageInfo(context.getPackageName(), 0);
            int versionCode = packageInfo.versionCode;
            String versionName=packageInfo.versionName;

            CommonTasks.showLog("Saving APP VersionCode and Version Name");

            // SAVE YOUR DATA

        }catch(Exception e){
        }
    }

Check App is Upgraded:

public static boolean isAppUpdated(Context context){
        boolean result=false;
        try{
            PackageInfo packageInfo = context.getPackageManager()
                    .getPackageInfo(context.getPackageName(), 0);
            int versionCode = packageInfo.versionCode;
            String versionName=packageInfo.versionName;

            String prevVersionName= GET STORED VERSION_NAME;
            if(prevVersionName!=null && !prevVersionName.equals("") &&
                    !prevVersionName.equals(versionName)){
                showLog("App Updated");
                result=true;
            }else{
                showLog("App Not updated");
            }

        }catch(Exception e){
        }
        return result;
    }

here, if isAppUpdated() return true means your app is updated.

Note, After checking upgrade issue, you must have to update the sharedPreferences. :)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to detect when android app has been upgraded?

From Dev

Detect which app has been launched in android

From Dev

How can I detect when a Cordova app has been removed from the recents menu, from within an Android plugin?

From Dev

How can I detect if an Angular app has been initialized from outside Angular?

From Dev

How can I detect if an Angular app has been initialized from outside Angular?

From Dev

How to detect a Winforms app has been idle for certain amount of time

From Dev

Meteor - How can I detect if an app has been opened?

From Dev

How to detect an iOS App installed or upgraded?

From Dev

In Android, how to detect a component (like TextView) has been drawn?

From Dev

How to detect in a generator that it has been interrupted from outside

From Dev

how to detect from a Vagrantfile if a plugin has been installed?

From Dev

How can I see when package has been upgraded?

From Dev

WPF how to detect listviewitem has been selected

From Dev

How to detect if an object variable has been changed?

From Dev

How to detect a file has been deleted

From Dev

How to detect if CurrentCulture has been customised by the user?

From Dev

How to detect a file has been deleted

From Dev

WPF how to detect listviewitem has been selected

From Dev

How can be detected when an app has been restored from a backup?

From Dev

How can be detected when an app has been restored from a backup?

From Dev

How to detect if app has been "minimized" by home button or hidden behind another activity

From Dev

Can an app detect that a file (image) has been copied off the device?

From Dev

How can I detect if a tcp connection has been forwarded from a ssl connection?

From Dev

How to detect what commit a branch has been created from in LibGit2Sharp

From Dev

Can my free Android app be upgraded to a paid version via in-app purchase AND paid store version?

From Dev

How to get x,y coordinates of a text that has been rotated by an angle in PIL python?

From Dev

Detect if an object has been disconnected from its clients

From Dev

Detect if new install or updated version (Android app)

From Dev

How to detect how often a button has been pushed consecutively?

Related Related

  1. 1

    How to detect when android app has been upgraded?

  2. 2

    Detect which app has been launched in android

  3. 3

    How can I detect when a Cordova app has been removed from the recents menu, from within an Android plugin?

  4. 4

    How can I detect if an Angular app has been initialized from outside Angular?

  5. 5

    How can I detect if an Angular app has been initialized from outside Angular?

  6. 6

    How to detect a Winforms app has been idle for certain amount of time

  7. 7

    Meteor - How can I detect if an app has been opened?

  8. 8

    How to detect an iOS App installed or upgraded?

  9. 9

    In Android, how to detect a component (like TextView) has been drawn?

  10. 10

    How to detect in a generator that it has been interrupted from outside

  11. 11

    how to detect from a Vagrantfile if a plugin has been installed?

  12. 12

    How can I see when package has been upgraded?

  13. 13

    WPF how to detect listviewitem has been selected

  14. 14

    How to detect if an object variable has been changed?

  15. 15

    How to detect a file has been deleted

  16. 16

    How to detect if CurrentCulture has been customised by the user?

  17. 17

    How to detect a file has been deleted

  18. 18

    WPF how to detect listviewitem has been selected

  19. 19

    How can be detected when an app has been restored from a backup?

  20. 20

    How can be detected when an app has been restored from a backup?

  21. 21

    How to detect if app has been "minimized" by home button or hidden behind another activity

  22. 22

    Can an app detect that a file (image) has been copied off the device?

  23. 23

    How can I detect if a tcp connection has been forwarded from a ssl connection?

  24. 24

    How to detect what commit a branch has been created from in LibGit2Sharp

  25. 25

    Can my free Android app be upgraded to a paid version via in-app purchase AND paid store version?

  26. 26

    How to get x,y coordinates of a text that has been rotated by an angle in PIL python?

  27. 27

    Detect if an object has been disconnected from its clients

  28. 28

    Detect if new install or updated version (Android app)

  29. 29

    How to detect how often a button has been pushed consecutively?

HotTag

Archive