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!
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.
You need to install your test app from Google Play; it won't work if you just install it from Android Studio.
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.
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.
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.
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.
Set versionCode
to 1, and do the same as step 1.
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.
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.
While the app is running, attach debugger (Android Studio -> Run -> Attach Debugger to Android Process).
Check the update (appUpdateManager.appUpdateInfo.addOnSuccessListener {...}
), start the update (appUpdateManager.startUpdateFlowForResult(...)
), etc.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With