I had an app on the playstore. Know what I want is when new update is available on playstore the user should get a popup to update the app when he try to use the app. And if he does not update the app it should close the app. Ex: I want to force the user to update the app to continue using.
Half a year ago, at the Android Dev Summit, Google announced a new way for developers to force their users to update their apps when they launch new features or important bug fixes.
The Play Store may not update your apps if your phone does not have the most recent Android version. Navigate to your phone's Settings > Software update. Download the new update if it's available. It'll automatically be installed on your phone if there is enough storage available.
Step 1: Long tap on Google Play Store and open the app info menu. Step 2: Go to Storage & cache menu. Step 3: Tap on Clear cache from the following menu. Close the app, open Google Play Store, and update apps without any hitch.
As far as I know Google Play doesn't provide with any kind of API for this, so you would have to manually check.
But I can tell you a method to force user to update with the latest release.
One way is by sending a push notification to the user, and when you receive the notification you redirect user to the playstore.
Second Method is longer but this is a proper sure method. You make a webservice on a server, which stores the latest version of the app. whenever your apps runs,
MainActivity
you make a post a request to the webservice and check if the version in the app is latest or notYou shouldn't need to force an update directly, the Play store will actually automatically update your application for users when you push updates out. Users don't have to take any action unless you've made changes to your permissions.
I would definitely recommend letting the Play store do its thing on its own... but I did do similar in one app.
Something like this should tell you the play store update dates and version:
SimpleDateFormat formatter = Dates.getSimpleDateFormat(ctx, "dd MMMM yyyy");
String playUrl = "https://play.google.com/store/apps/details?id=" + appPackageName;
RestClient restClient = /* Some kind of rest client */
try {
String playData = restClient.getAsString(playUrl);
String versionRaw = findPattern(playData, "<([^>]?)*softwareVersion([^>]?)*>([^<]?)*<([^>]?)*>");
String updateRaw = findPattern(playData, "<([^>]?)*datePublished([^>]?)*>([^<]?)*<([^>]?)*>");
Date updated = formatter.parse(updateRaw.replaceAll("<[^>]*>", "").trim());
String version = versionRaw.replaceAll("<[^>]*>", "").trim();
_currentStatus = new PlayStatus(version, updated, new Date());
} catch (Exception e) {
_currentStatus = new PlayStatus(PlayStatus.UNKNOWN_VERSION, new Date(0), new Date(0));
}
My PlayStatus class had a method like the following:
public boolean hasUpdate() {
int localVersion = 0;
int playVersion = 0;
if (! versionString.equals(UNKNOWN_VERSION)) {
localVersion = Integer.parseInt(BuildConfig.VERSION_NAME.replace(".",""));
playVersion = Integer.parseInt(versionString.replace(".",""));
}
return (playVersion > localVersion);
}
You can't update the app directly obviously, but if you determine the version is out of date you can present an Intent to the user that will take them to the Play Store:
public static void updateApp(final Activity act) {
final String appPackageName = BuildConfig.APPLICATION_ID;
AlertDialog.Builder builder = new AlertDialog.Builder(act);
builder
.setTitle(act.getString(R.string.dialog_title_update_app))
.setMessage(act.getString(R.string.dialog_google_credentials_message))
.setNegativeButton(act.getString(R.string.dialog_default_cancel), null)
.setPositiveButton(act.getString(R.string.dialog_got_it), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
try {
act.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
} catch (ActivityNotFoundException anfe) {
act.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName;)));
}
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
I believe this was compiled against API 21, so there might be a couple small tweaks for 22.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With