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 {
}
});
}