Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AppUpdateManager.startUpdateFlowForResult not showing dialog

I am trying to implement android in-app updates. I am following the tutorial given in the official portal but the dialog is not shown when startUpdateflow method is called. Please find below is the chunk of code I am executing.

final AppUpdateManager appUpdateManager = AppUpdateManagerFactory.create(this);
    Task<AppUpdateInfo> appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();
    appUpdateInfoTask.addOnSuccessListener(new OnSuccessListener<AppUpdateInfo>() {
        @Override
        public void onSuccess(AppUpdateInfo appUpdateInfo) {
            try {
                Toast.makeText(getApplicationContext(),"Success.", Toast.LENGTH_SHORT).show();
                appUpdateManager.startUpdateFlowForResult(
                        appUpdateInfo,
                        AppUpdateType.FLEXIBLE,
                        SplashScreenActivity.this,
                        APP_UPDATE_REQUEST_CODE
                );
            } catch (IntentSender.SendIntentException e) {
                Toast.makeText(getApplicationContext(),"Exception received", Toast.LENGTH_SHORT).show();
                e.printStackTrace();
            }
        }
    });

I am able to see Success toast and the line

appUpdateManager.startUpdateFlowForResult() is called

but this is not showing update dialog with No Thanks and Update buttons as shown in the portal. I tried using FakeAppUpdateManager too but that also didn't help.

Requesting help here!

like image 514
Varun A M Avatar asked Aug 17 '19 08:08

Varun A M


2 Answers

Here is what I noticed; in other words, your mileage may vary.

In-app Update works as advertised, but in order for it to work the way you expect it to, there are a few things that need to be in place.

  1. You need to install your test app from Google Play; it won't work if you just install it from Android Studio.

  2. Installing it from Google Play can be done via "Open testing", "Closed testing", or "Internal testing", but (I think) those tracks allow only release builds (i.e. can't set breakpoints), so I suggest you start with "Internal app sharing". Just upload your .apk or .aab to https://play.google.com/console/internal-app-sharing. The only thing that doesn't seem to work is setting the update priority in "Internal app sharing". I'd like to hear how others handle it.

  3. FakeAppUpdateManager does NOT show the update dialog. You just mock what Google Play would do by issuing commands, such as fakeAppUpdateManager.downloadStarts(), but there won't be any dialogs. Refer to this.

  4. An update can be both FLEXIBLE and IMMEDIATE at the same time. In other words, if you check appUpdateInfo.isUpdateTypeAllowed(FLEXIBLE) and appUpdateInfo.isUpdateTypeAllowed(IMMEDIATE), they can be both true. It's up to you to decide what to do at that point, depending on what the update's priority is.

These are the steps I took.

  1. Set versionCode to 2, build either .apk or .aab (in debug version), and upload it to "Internal app sharing". Make note of its download URL.

  2. Set versionCode to 1, and do the same as step 1.

  3. Open the URL from step 2 (i.e. version 1) from the phone. It will open Google Play and ask you to download the app. Download, and open it.

  4. Open the URL from step 1 (i.e. version 2) from the phone, but DON'T tap on the "Update" button; just bring the app version 1 to the foreground.

  5. While the app is running, attach debugger (Android Studio -> Run -> Attach Debugger to Android Process).

  6. Check the update (appUpdateManager.appUpdateInfo.addOnSuccessListener {...}), start the update (appUpdateManager.startUpdateFlowForResult(...)), etc.

like image 117
solamour Avatar answered Sep 27 '22 23:09

solamour


I was facing the same problem. I found this in the doc for the method startUpdateFlowForResult in the com.google.android.play.core.appupdate.AppUpdateManager class

Each {@link com.google.android.play.core.appupdate.AppUpdateInfo AppUpdateInfo} instance can be used only in a single call to this method. If you need to call it multiple times - for instance, when retrying to start a flow in case of failure you need to get a fresh {@link com.google.android.play.core.appupdate.AppUpdateInfo AppUpdateInfo} from {@link #getAppUpdateInfo()}.

So, getting new instance after canceled or failed update did the trick

like image 24
S.Slavova Avatar answered Sep 28 '22 01:09

S.Slavova