问题
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$
回答1:
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.
来源:https://stackoverflow.com/questions/25666381/how-can-i-make-my-outdated-app-version-show-a-dialog-that-an-update-is-available