Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force app to update when new version of app is available in android play store

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.

like image 467
Neerav Shah Avatar asked Apr 11 '15 06:04

Neerav Shah


People also ask

Can you force an app to update?

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.

Why apps are not updating automatically in Play Store?

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.

How do I update my apps on Android that won't update?

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.


2 Answers

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.

  1. One way is by sending a push notification to the user, and when you receive the notification you redirect user to the playstore.

  2. 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,

    • on MainActivity you make a post a request to the webservice and check if the version in the app is latest or not
    • If it is not the latest version, on the response of the webservice you can redirect user to the playstore
like image 85
Jeffy Lazar Avatar answered Sep 21 '22 02:09

Jeffy Lazar


You 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.

like image 37
Crias Avatar answered Sep 18 '22 02:09

Crias