Android In app force update implementation

Android In app force update implementation

Android development, Android tutorial

Hi, Developer in this Android article I am sharing how to use in App force update in Android. If you want to control your App user always uses an updated version of your App so you can control your App show an update popup when a new version of your App live on the play Store.

Android in-app force update implementation is very helpful to version control user Always update version on you App. for implementation follows these step. google Doc  for Android in-app force update

Setup 1:  Add Google core Library in your app build Gradle.

implementation 'com.google.android.play:core:1.8.0'

Setup 2: Add these codes where you want to check the Update App.

 public void UpdateApp(){
        AppUpdateManager appUpdateManager = AppUpdateManagerFactory.create(this);
        Task<AppUpdateInfo> appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();
        // Checks that the platform will allow the specified type of update.
        appUpdateInfoTask.addOnSuccessListener(result -> {

            if (result.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE) {
//                requestUpdate(result);
                android.view.ContextThemeWrapper ctw = new android.view.ContextThemeWrapper(this,R.style.Theme_AlertDialog);
                final android.app.AlertDialog.Builder alertDialogBuilder = new android.app.AlertDialog.Builder(ctw);
                alertDialogBuilder.setTitle("Update NTT Netmagic");
                alertDialogBuilder.setCancelable(false);
                alertDialogBuilder.setIcon(R.drawable.icons_google_play);
                alertDialogBuilder.setMessage("Fitness Trainer recommends that you update to the latest version for a seamless & enhanced performance of the app.");
                alertDialogBuilder.setPositiveButton("Update", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        try{
                            startActivity(new Intent("android.intent.action.VIEW", Uri.parse("market://details?id="+getPackageName())));
                        }
                        catch (ActivityNotFoundException e){
                            startActivity(new Intent("android.intent.action.VIEW", Uri.parse("https://play.google.com/store/apps/details?id="+getPackageName())));
                        }
                    }
                });
                alertDialogBuilder.setNegativeButton("No Thanks",new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {

                    }
                });
                alertDialogBuilder.show();

            } else {

            }
        });
    }

copy the method and past you java file and call method where you want to check App update and there more type of in-app update with google core library I you want to read more and other like kotlin Follow Google Documents