Force Android app update when a new version is available

I have an application in the Google Play store. When the update version is available, the older version will become unusable, that is, if users do not update the application, they will not enter the application. How can I get users to update the application when a new version becomes available?

+80
android
Oct 08 '13 at 9:44
source share
18 answers

I agree with Scott Helme's point above. But in some extreme situations (security issues, violation of APIs ...), where you absolutely need users to update to continue using the application, you could provide a simple version control API. The API will look like this:

versionCheck API:

Request Parameters:

  • int appVersion

Answer

  • boolean forceUpgrade
  • boolean recommendUpgrade

When your application starts, you can call this API, which will be passed in the current version of the application, and check the response to the version control API call.

If forceUpgrade is true , display a pop-up dialog with options to either allow the user to exit the application or go to the Google Play Store to update the application.

Otherwise, if recommendUpgrade true , show a pop-up dialog box with options for updating or continuing to use the application.

Even with this forced upgrade capability, you should continue to support older versions, if absolutely necessary.

+83
Dec 06 '13 at 6:18
source share

try this: first you need to make a call request to the PlayStore link, get the current version from there and then compare it with your current version.

 String currentVersion, latestVersion; Dialog dialog; private void getCurrentVersion(){ PackageManager pm = this.getPackageManager(); PackageInfo pInfo = null; try { pInfo = pm.getPackageInfo(this.getPackageName(),0); } catch (PackageManager.NameNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } currentVersion = pInfo.versionName; new GetLatestVersion().execute(); } private class GetLatestVersion extends AsyncTask<String, String, JSONObject> { private ProgressDialog progressDialog; @Override protected void onPreExecute() { super.onPreExecute(); } @Override protected JSONObject doInBackground(String... params) { try { //It retrieves the latest version by scraping the content of current version from play store at runtime Document doc = Jsoup.connect(urlOfAppFromPlayStore).get(); latestVersion = doc.getElementsByClass("htlgb").get(6).text(); }catch (Exception e){ e.printStackTrace(); } return new JSONObject(); } @Override protected void onPostExecute(JSONObject jsonObject) { if(latestVersion!=null) { if (!currentVersion.equalsIgnoreCase(latestVersion)){ if(!isFinishing()){ //This would help to prevent Error : BinderProxy@45d459c0 is not valid; is your activity running? error showUpdateDialog(); } } } else background.start(); super.onPostExecute(jsonObject); } } private void showUpdateDialog(){ final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("A New Update is Available"); builder.setPositiveButton("Update", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse ("market://details?id=yourAppPackageName"))); dialog.dismiss(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { background.start(); } }); builder.setCancelable(false); dialog = builder.show(); } 
+49
Oct 05 '15 at 6:52
source share

You should not stop supporting the old version as soon as the new version is released. This will lead to a terrible user. I do not know of any software manufacturer who does this for a good reason.

What happens if the user is unable to update or does not want at this time? They simply cannot use your application, which is bad.

Google does not provide any versioning options, so you have to minimize your own. A simple web service will be enough to return the current version that your application can check. Then you can update the version and the application will know that it is out of date. I would recommend using this so that your users know that there is an update faster than depending on Google Play. In fact, this should not be used to prevent the application from working, just for the user to update it.

+45
Oct 08 '13 at 9:56
source share

Scott and Michael answer correctly. Build a service that provides the minimum version number that you support and compare it with the installed version. You hopefully should never use this, but it is a life saver, if some version is there, you absolutely must kill because of some serious flaw.

I just wanted to add code for what to do next. Here's how you then launch the Google Play intent and send them to your new version in the store after asking the user that they should be updated.

 public class UpgradeActivity extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_upgrade); final String appName = "com.appname"; Button button = (Button) findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+appName))); } }); } } 

You should review your design if you need to force update each version.

+16
Jan 31 '14 at 16:31
source share

Solution from the Google Team

Starting with Android 5.0, this is easy to achieve with the new Google Play In App update mechanism. Requirements must have a Play Core version 1.5 library. 0+ and use App Bundles app distribution instead of apks.

The library provides you with 2 different ways to notify users of an update:

  1. Flexibility when users can continue to use the application while it is updating in the background.

  2. Immediately - a lock screen that prevents the user from entering the application until they update it.

There are the following steps for its implementation:

  1. Check for Updates
  2. Start update
  3. Get a call back to update status
  4. Handle update

All these implementation steps are described in detail on the official website: https://developer.android.com/guide/app-bundle/in-app-updates

+13
May 08 '19 at 7:36
source share

I highly recommend checking out Firebase Remote Config for this.

I implemented it using the parameter - app_version_enabled - with the condition "Disabled Android Versions", which looks like this:

 applies if App ID == com.example.myapp and App version regular expression ^(5.6.1|5.4.2) 

The default value is true, but Disabled Android Versions is false. In my regex for disabled versions of Android, you can add more disabled versions just with a different |{version name} inside these parentheses.

Then I just check if the configuration is allowed by the version or not. I have an activity that I run that causes the user to update. I check only two places from which the application can be launched from outside (my default launch activity and intent processing activity). Since Remote Config works in the cache, it will not immediately capture "disabled" versions of the application if the required time has not passed for the cache to be invalid, but this is no more than 12 hours if you go over their recommended cache expiration value.

+4
Dec 13 '16 at 23:39
source share

Google officially provides the Android API for this.

The API is currently being tested with several partners and will soon be available to all developers.

+4
Nov 09 '18 at 14:17
source share

It is better to define our own process for updating.

  • Create a web service that provides the latest version of the application (ios, android) from our server.
  • Or any web service that you used in the application (for example, Login) will return the latest version of the application from the server.
  • After the application receives a C # 1 or 2 version. The application will override it using local / cuurent appversion. if there is a difference, we can show the warning as follows:

Android and iOS: If the latest version of the application is available, it will display a warning like "Last version available with additional features", "Update", click the "Update" button (warn the "Upgarde" and "No Thanks" buttons). Then the application will be redirected to playstore / Appstore and open the latest version.

  --- we can do upgrade compulsory or optionally. 

Before upgrading, make sure that you have processed the proper db migration process if there is a change to the db schema.

+2
May 26 '15 at 10:22
source share

check local version code and play store apk

 try { versionChecker VersionChecker = new versionChecker(); String versionUpdated = VersionChecker.execute().get().toString(); Log.i("version code is", versionUpdated); PackageInfo packageInfo = null; try { packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } int version_code = packageInfo.versionCode; String version_name = packageInfo.versionName; Log.i("updated version code", String.valueOf(version_code) + " " + version_name); if (version_name != versionUpdated) { String packageName = getApplicationContext().getPackageName();// UpdateMeeDialog updateMeeDialog = new UpdateMeeDialog(); updateMeeDialog.showDialogAddRoute(MainActivity.this, packageName); Toast.makeText(getApplicationContext(), "please updated", Toast.LENGTH_LONG).show(); } } catch (Exception e) { e.getStackTrace(); } 

implement class to check version

 class versionChecker extends AsyncTask<String, String, String> { String newVersion; @Override protected String doInBackground(String... params) { try { newVersion = Jsoup.connect("https://play.google.com/store/apps/details?id=+YOR_PACKAGE_NAME+&hl=en") .timeout(30000) .userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6") .referrer("http://www.google.com") .get() .select("div[itemprop=softwareVersion]") .first() .ownText(); } catch (IOException e) { e.printStackTrace(); } return newVersion; } } 

Dialog Box for Update

 public class UpdateMeeDialog { ActivityManager am; TextView rootName; Context context; Dialog dialog; String key1,schoolId; public void showDialogAddRoute(Activity activity, final String packageName){ context=activity; dialog = new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(false); dialog.setContentView(R.layout.dialog_update); am = (ActivityManager)activity.getSystemService(Context.ACTIVITY_SERVICE); Button cancelDialogue=(Button)dialog.findViewById(R.id.buttonUpdate); Log.i("package name",packageName); cancelDialogue.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("https://play.google.com/store/apps/details? id="+packageName+"&hl=en")); context.startActivity(intent); } }); dialog.show(); } } 

Dialog window

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#d4e9f2"> <TextView android:layout_width="match_parent" android:layout_height="40dp" android:text="Please Update First..!!" android:textSize="20dp" android:textColor="#46a5df" android:textAlignment="center" android:layout_marginTop="50dp" android:id="@+id/textMessage" /> <LinearLayout android:layout_width="match_parent" android:orientation="horizontal" android:weightSum="1" android:layout_marginTop="50dp" android:layout_below="@+id/textMessage" android:layout_height="50dp"> <Button android:id="@+id/buttonUpdate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="Update" android:background="#67C6F1" android:textAlignment="center" /> </LinearLayout> 

+2
Oct. 06 '17 at 9:43 on
source share

Google introduced the update library in the application, ( https://developer.android.com/guide/app-bundle/in-app-updates ), it works on Lollipop + and gives you the opportunity to ask the user to update with a good dialog (FLEXIBLE) or with mandatory full-screen message (IMMEDIATE).

You need to implement the latter. Here's how it would look: enter image description here

I covered all the code in this answer: stack overflow

+2
Jun 28 '19 at 14:16
source share

To force the user of the application to be updated if the update is available on the market, you must first check the version of the application on the market and compare it with the version of the application on the device. If they are different, this may be an available update. In this post, I wrote down the code to get the current version of the market and the current version on the device and compared them together. I also showed how to show the update dialog and redirect the user to the update page. Go to this link: https://stackoverflow.com/a/166268/168328 ... Just make sure that in the dialog box you only show the user’s refresh button and don’t show the cancel button. In this case, he will be forced to update before he can use the application.

+1
Feb 13 '16 at 19:24
source share

What should definitely be mentioned here is the imminent release of the In-app Updates API .

You will have two options with this API; the first is full-screen mode for critical updates, when you expect the user to wait for the update to be applied immediately. The second option is a flexible update, which means that the user can continue to use the application while the update is downloaded. You can fully customize the update process so that it looks like part of your application.

+1
Jan 29 '19 at 9:09 on
source share

you can do this by matching the version number stored in the application in a variable and the current version of the application is stored on the server side in the same way, and each time the user opens the application, the first request should be sent to verify that if he found a match, don’t do anything, just let the user use your application, otherwise aim for the Google game store or open a web browser for your application (window.open (" https://play.google.com/store/apps/details ? id = packag e_name ", '_system', 'location = yes');), and there they will automatically have a button requesting updates, which is what the Google PlayStore does for you if you do not have automatic updates.

0
Mar 06 '16 at 7:49
source share

You can notify your users about the availability of a new version of the current application for updating. In addition, if this condition is true, you can block the entrance to the application.

See if this will provide you with a solution.

0
Oct 12 '16 at 18:45
source share

Well, there can be many solutions to this problem, for example, removing the version code from the application page (Google Play application page), etc.

But I'm going to show you the final solution, which will not cost a penny and will work as if by magic.

  1. Just save the latest version of your application code to Firebase Remote
    Settings panel
  2. Get the value of the version code each time the application starts
  3. Compare it with the current version of the application code, which you can get with the following code

     private int getCurrentVersionCode() { try { return getPackageManager().getPackageInfo(getPackageName(), 0).versionCode; } catch (NameNotFoundException e) { e.printStackTrace(); } return -1; 

    }

If the extracted version code is larger than the current version, show AlertDialog asking you to update the application. Otherwise, the application is already updated.

Thus, whenever you roll out a new version, you must put this code of the new version in the Firebase Remote configuration panel.

You can read the entire tutorial on how to get users to update the application using Firebase Remote Config.

0
Jun 21 '19 at 10:38 on
source share

It is recommended that you use the remote configuration for the version of the application, and always check the activity at startup if the current version of the application matches the remote version or not, if there is no forced update for the application store.

Simple logic of happy coding ..

https://firebase.google.com/docs/remote-config/android

0
Jun 21 '19 at 11:15
source share

Use appgrades.io Just integrate the SDK, and using the toolbar you can easily block any version by setting a custom view / pop-up window that will be displayed for your users asking them to update them.

-one
Apr 04 '18 at 21:01
source share

Google has released In-App Updates for the Play Core library.

I implemented a lightweight library to easily implement updates in the application. You can find at the following link an example of how to force the user to perform an update.

https://github.com/dnKaratzas/android-inapp-update#forced-updates

-2
Jul 21 '19 at 13:15
source share



All Articles