0

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.

Al Walid Ashik
  • 1,545
  • 20
  • 32
  • 1
    It will only work if you have downloaded it from playstore – Maitri Oct 17 '19 at 06:54
  • I've downloaded it from playstore. it shows the update dialog. but it's showing update dialog again and again even the updated version is installed! – Al Walid Ashik Oct 17 '19 at 07:00
  • your requestUpdateApp() function might be the reason of it.. Whats is in that function? – Maitri Oct 17 '19 at 07:11
  • where I'm checking and requesting new update. I guess that method is fine cause it doesn't get called! after debugging, I understood that my playstore version of update is not actually getting installed. but In App Update shows downloaded and installed! – Al Walid Ashik Oct 17 '19 at 07:22
  • any update about this problem ? how you solve this issue, i got the same problem – Yudi karma Oct 31 '19 at 11:27
  • @Yudikarma, I'm sorry to tell you that there is no way I could fix this issue. It seems to me this issue exist in there api. So I implemented so called manual way to show update instead! – Al Walid Ashik Nov 03 '19 at 08:49

1 Answers1

2

for anyone cant install update apk from playstore. the wrong is not your code, but way your test this library.

  1. you test your function with upload news release (after add in app update libs) to playstore with increment version code and version name.

  2. then you decrement or -1 your version and version code, then build news release apk and try install in your device. and update is show, but install is failed. cause after succes install you find your version code apk keep with old version. and pop up update keep show and again and again.

the right way for test is like this :

  1. you test your function with upload news release (after add in app update libs) to playstore with increment version code and version name. install your news version from playstore

  2. then you increment or +1 your version and version code, then build news release apk or bundle and upload again to playstore with news release.

  3. then wait for apk or bundle live in playstore (until you see “Update” in your playstore), if app already live in playstore, but you not found “update” in your app. you can clear all data in playstore and open search again your app in playstore and you will found “Update”

  4. open your apk and you will find show pop up update, and update must be succes.

Yudi karma
  • 324
  • 3
  • 15