Libraries:
implementation 'com.google.android.play:core:1.7.3'
implementation 'com.google.android.play:core-ktx:1.7.0'
Additional information:
Everything else regarding app updates and internal app sharing works for me, I do get dialog with update mentioned, if I don't use condition for daysAvailable in my if statemants.
1.) I'm implementing in app updates according to documentation found here.
// Returns an intent object that you use to check for an update.
val appUpdateInfoTask = appUpdateManager.appUpdateInfo
// Checks whether the platform allows the specified type of update,
// and checks the update priority.
appUpdateInfoTask.addOnSuccessListener { appUpdateInfo ->
val daysAvailable = appUpdateInfo.clientVersionStalenessDays() ?: 0
Toast.makeText(this, "Update availbable for $daysAvailable days", Toast.LENGTH_LONG).show()
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
&& daysAvailable >= DAYS_FOR_FLEXIBLE_UPDATE
&& appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) {
startUpdate(appUpdateInfo, appUpdateManager, AppUpdateType.FLEXIBLE, REQUEST_CODE_UPDATE_FLEXIBLE)
} else if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
&& daysAvailable > DAYS_FOR_IMMEDIATE_UPDATE
&& appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
startUpdate(appUpdateInfo, appUpdateManager, AppUpdateType.IMMEDIATE, REQUEST_CODE_UPDATE_IMMEDIATE)
}
}
To try this out through google play, i'm using internal app sharing method. So I have actually 3 version of the app uploaded on internal app sharing. So i click on first apk, which has version number v200, then i click on link for version 201 but as per guide, i don't click install. I wait 1 or 2 days, but appUpdateInfo.clientVersionStalenessDays()
is still returning null, even after a couple of days since I clicked on second version apk link (v201). My first question is, why is this method always returning null for me, even though it knows that there is newer update available?
2.) My second question is regarding appUpdateInfo.clientVersionStalenessDays()
itself. Lets say it's Monday and user has version 200 installed and we release version 201 and it's available to him on Tuesday. Theoretically, on Thursday appUpdateInfo.clientVersionStalenessDays()
should return 2 (as in for 2 days this user have update available). But he still didn't choose to update. And then on friday we release version 202 and it's available to him on Saturday. On Sunday, what should above method return? 1 or 5? **So my second question is basically, does this method counter resets when there is newer version available to user, does it reset when we release version v202? (will this method check for how long was version 202 available for him, or just update in general?).
Let me know if I should provide any additional information regarding my issues.
Its not working in the internal app sharing and returns null. You can check Build version, and if build version equal debug - use mocked value