0

I am just new to android programming, so let's say i have an app of version 1.0 .. then i released another version for the same app, let's say version 1.1 .. what code should i add in my app to check for updates and forces the outdated app versions to exit when a user does not update it and redirects the user to the download link if he/she wants to update my app ?. thanks

in short, the outdated apps cannot be used because an alert dialog will appear that tells the user he must update my app to a newer version available

PS, my app is not in the Play Store yet .. as i am a new android programmer and i have no 25$

Sagar Pilkhwal
  • 3,998
  • 2
  • 25
  • 77
n00b
  • 51
  • 2
  • 7
  • 1
    Hi welcome to SO. Please [take the tour](http://stackoverflow.com/tour) and use the [search function](http://stackoverflow.com/search). possible duplicate of [Android Application Update Notification](http://stackoverflow.com/questions/10119092/android-application-update-notification) or http://stackoverflow.com/questions/4635042/android-notify-user-of-a-newer-version or http://stackoverflow.com/questions/16466516/notify-user-within-app-that-a-new-version-is-available OR http://stackoverflow.com/questions/9849889/how-to-notifiy-users-about-an-android-app-update – RossC Sep 04 '14 at 13:09

1 Answers1

2

you can build the alert dialog on the first version, when you upload new version to google play you can notify your app with gcm. and ask it to show the alertDialog.

1.save appVersion variable in sharedPref.

2.in your application startup :

if(appVersion !=  getAppVersion(context))
{
   showAlertDialog()
}


private static int getAppVersion(Context context) {
    try {
        PackageInfo packageInfo = context.getPackageManager()
                .getPackageInfo(context.getPackageName(), 0);
        return packageInfo.versionCode;
    } catch (NameNotFoundException e) {
        // should never happen
        throw new RuntimeException("Could not get package name: " + e);
    }
}

3.when you have a new update,send the new version number (by gcm) and edit your sharedPref.

user3376296
  • 71
  • 1
  • 2