I would like to implement a check in my application to tell the user when I have distributed a new version out on android markets. Any ideas of an easy and good way to implement this check?
Update This is how i resolved it:
private static int getManifestVersionCode(Activity activity) {
try {
PackageInfo pinfo = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0);
return pinfo.versionCode;
} catch (NameNotFoundException e) {
}
return 0;
}
private static int getRemoteVersionCode() {
BufferedReader reader = null;
try {
URL url = new URL("http://myserver.com/my_version_code.html");
reader = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
String line = reader.readLine();
return Integer.parseInt(line);
}catch (Exception e) {
}finally {
if (reader != null){
try {
reader.close();
} catch (IOException logOrIgnore) {
}
}
}
return 0;
}
The User is already notified about updates when they use the Market application.
But if you insist on having another method in your application the easiest thing to do would be to have an Asynchronous call from the application to a remote server where the application version is compared to the current version.
Update:
If you rely on screen scraping then if Google were to change the page you’re update check wouldn’t work. In which case the users won’t be alerted. So for that reason I think it’s best if you host the server side part yourself, if you can pay for the server. You could do it another way (which I don’t really like) but it’s free, store a public html file on something like dropbox which the app can read the from and then you can scrape the html. Since it’s your html page you won’t have an issue of the page changing.