Android In-App update API return 0 as availableVersionCode & updateAvailability as 1 (UPDATE_NOT_AVAILABLE)
Asked Answered
A

3

6

I'm trying to implement the in-app update API, followed in-app-update-api, when debugging the app with lower version than play store version, AppUpdateInfo return availableVersionCode as 0 and updateAvailability as 1 (UPDATE_NOT_AVAILABLE), Note: I've used the same package name & same signing key to run a build

Thanks in advance!

Aquila answered 22/5, 2019 at 9:29 Comment(2)
Have you found a solution to this problem?Slipon
Yes, I just uploaded the apk to beta version app in play store, and checked with lower version of release apk with my deviceAquila
M
6

The most likely reason is that the Play Store on your device hasn't learnt about the new update yet.

After you release your update in the Play Developer Console, the information about this update does not reach immediately all devices; some Play Store background job on the device is responsible for periodically checking for updates for installed apps and refresh the on-device cached information.

"But I want to test the behaviour on my device now, I don't want to wait for a background job to complete before I can test. Can I force the refresh of this cache?"

Yes, take a look at the last item of the Troubleshooting section here: https://developer.android.com/guide/app-bundle/in-app-updates#troubleshoot To refresh the cache you need to: close the Play Store; reopen it; navigate to the "My Apps & Games" app.

"Will my users need to do this too?"

No: your users can just wait for the background job to run.

Masterson answered 30/5, 2019 at 17:59 Comment(4)
can you tell us if it works for internal test track release as well?Slipon
I mean will the availableVersionCode will pick from the internal test track release or it will only fetch the values from the published public version?Slipon
If your account is opted-in to the internal test program, it will be able to update to a version that was uploaded to the internal test track.Masterson
I've asked the question here #56581800 Can you please help us out?Slipon
O
0

At least you should download the app from Play Store. This because the device must know exact information about the application.

Organizer answered 20/12, 2019 at 9:1 Comment(0)
M
-2

I also had the exactly same problem, and I solved it. You should check what kind of context you are passing to create AppUpdateManager. It seems like you need to pass global app context when creating AppUpdateManager.

So if you are just passing "this" or some other activity context, change it to "Global App Context".

From

AppUpdateManager appUpdateManager = AppUpdateManagerFactory.create(this);

to

AppUpdateManager appUpdateManager = AppUpdateManagerFactory.create(getApplicationContext());

According to the documentation context is the application Context for your app

enter image description here

Megawatt answered 24/5, 2019 at 5:13 Comment(5)
Hi! I've worked on this Play feature and I believe that it should not matter whether you use the ApplicationContext or the Activity here. I would like to understand more about whether switching to application context has actually solved your problem (surprising) or if maybe by waiting long enough, my solution kicked in.Masterson
Oh, sorry but switching context actually solved problem in my case. And I had an app which had updated a few weeks ago at the moment I tested this code. It's quite weird if your comment is right..Megawatt
I checked my code again, and I found that I pass a wrong parameter if I just use 'this' for referring the app context. To sum up, my solution actually worked, but it's not because the AppUpdateManager requires global app context, but because I just passed wrong parameter to the API.Megawatt
@Megawatt but the API only accepts a Context. How could you be passing the wrong parameter if the only 2 compilable options are either the Activity or the ApplicationContext?Salchunas
According to the documentation it should be the application contextSoteriology

© 2022 - 2024 — McMap. All rights reserved.