Android In app force update implementation

Android In app force update implementation

Hi Developer in these Android article I am sharing how to used in App force update in Android. If you want to control you App user always use update version of your App so you can control your App show update popup when new version of your App live on play Store.

Android in app force update implementation is very helpful to version control user user Always update version on you App. for implementation follow 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 code where you want check 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 

Facebooktwitterredditpinterestlinkedinmail
Recommended
Hi Developer in this Android tutorial we are sharing how…