0

I'm trying to create an AlertDialog that always forces the user to update the app and always use the current one

But when putting this code it does not appear, even the trial version is inferior to the one from the Google Play store

Google Play:
versionCode: 6
versionName "1.6"

Test:
versionCode 4
versionName "1.4"

Below is the code used:

@Override
 public void onStart() {
     super.onStart();
     UpdateApp();
 }




    public void UpdateApp() {
        AppUpdateManager appUpdateManager = AppUpdateManagerFactory.create(this);
        Task<AppUpdateInfo> appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();

        appUpdateInfoTask.addOnSuccessListener(result -> {

            if (result.updateAvailability() != UpdateAvailability.UPDATE_AVAILABLE ){

                android.view.ContextThemeWrapper ctw = new android.view.ContextThemeWrapper(this, R.style.AlertDialog_AppCompat_Light);
                final android.app.AlertDialog.Builder alertDialogBuilder = new android.app.AlertDialog.Builder(ctw);
                alertDialogBuilder.setTitle("NOVA VERSAO");
                alertDialogBuilder.setCancelable(false);
                alertDialogBuilder.setMessage("Uma nova atualizacao esta disponivel na loja, realize atualizacao do mesmo para ter uma melhor experiencia");
                alertDialogBuilder.setPositiveButton("ATUALIZAR", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        try {
                            startActivity(new Intent("android.intent.action.VIEW", Uri.parse("https://play.google.com/store/apps/details?id=com.glam33.dpms&hl=pt-BR")));
                        } catch (ActivityNotFoundException e) {
                            startActivity(new Intent("android.intent.action.VIEW", Uri.parse("https://play.google.com/store/apps/details?id=com.glam33.dpms&hl=pt-BR")));
                        }
                    }
                });
                alertDialogBuilder.setNegativeButton("CANCELAR", new DialogInterface.OnClickListener() {


                    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
                    public void onClick(DialogInterface dialog, int id) {
                        finishAffinity();
                    }
                });
                alertDialogBuilder.show();

            } else {

            }
        });
    }

  • To work with AppUpdateManager you need to create a release variant build. I hope you are trying your changes with it only – hardik9850 Oct 19 '22 at 12:01
  • sorry but could you give me an example – Denis Oliveira Lazarini Oct 19 '22 at 12:32
  • Sure. I assume you have not set up an internal app-sharing option. Please do that first and later follow the steps given here https://developer.android.com/guide/playcore/in-app-updates/test#internal-app-sharing – hardik9850 Oct 20 '22 at 06:40
  • https://stackoverflow.com/questions/55939853/how-to-work-with-androids-in-app-update-api this will be of help as well – hardik9850 Oct 20 '22 at 06:41

0 Answers0