Recently I've added In App Update feature in my App with IMMEDIATE update flow. Here is I'm checking and requesting for the update in onCreate()
of MainActivity
initialized the variable in onCreate()
like this
appUpdateManager = AppUpdateManagerFactory.create(this);
appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();
and in onCreate(), I've added this piece of code
appUpdateInfoTask.addOnSuccessListener(appUpdateInfo -> {
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
Toast.makeText(app, "update available", Toast.LENGTH_SHORT).show();
//update is available
try {
appUpdateManager.startUpdateFlowForResult(appUpdateInfo, AppUpdateType.IMMEDIATE, this, Constant.APP_UPDATE_RQ_CODE);
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
Log.e(TAG, "Update app error: " + e.getMessage());
Toast.makeText(app, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
And this code in onActivityResult()
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == Constant.APP_UPDATE_RQ_CODE) {
if (requestCode == RESULT_OK){
//update is failed, request update again
Toast.makeText(app, "this is called again and again!", Toast.LENGTH_SHORT).show();
requestUpdateApp();
}
}
}
The problem is, after updating the app, always appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
gets true and that's why in app update dialog shows again and again. Please help me to resolve this issue.