I am using In-App Update API
in the application for Update Application while the new version is available in play store.
module gradle
defaultConfig {
applicationId "xxx.xxxxx"
minSdkVersion 21
targetSdkVersion 28
versionCode rootProject.ext.vCode
versionName rootProject.ext.vName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Last upload version(Live in Playstore)
vCode = 5
vName = "1.0.4"
project gradle (downgrade it for the testing)
vCode = 4
vName = "1.0.3"
Downgrade this version for the testing update available or not.
MainActivity.kt
class MainActivity : AppCompatActivity() {
private var appUpdateManager: AppUpdateManager? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
appUpdateManager = AppUpdateManagerFactory.create(this)
}
override fun onResume() {
super.onResume()
checkForVersionUpdate()
}
private fun checkForVersionUpdate() {
appUpdateManager?.appUpdateInfo?.addOnSuccessListener { appUpdateInfo ->
if ((appUpdateInfo.updateAvailability() == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS)) {
// If an in-app update is already running, resume the update.
startUpdateFlow(appUpdateInfo)
} else if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
&& appUpdateInfo.isUpdateTypeAllowed(IMMEDIATE)) {
startUpdateFlow(appUpdateInfo)
}
}
}
private fun startUpdateFlow(appUpdateInfo: AppUpdateInfo) {
try {
appUpdateManager?.startUpdateFlowForResult(
appUpdateInfo,
IMMEDIATE,
this,
123)
} catch (e: InvocationTargetException) {
e.printStackTrace()
} catch (e: IntentSender.SendIntentException) {
e.printStackTrace()
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == 123) {
if (resultCode != RESULT_OK) {
Log.i("Update failed code:", resultCode.toString())
// If the update is cancelled or fails,
// you can request to start the update again.
} else if(resultCode == RESULT_CANCELED)
checkForVersionUpdate()
}
}
}
I last uploaded build in play store with App Bundle(.aab) and Open Beta.
Tried following ways.
Use internal app sharing to test in-app updates by performing the following steps: Make sure your test device has a version of your app installed that supports in-app updates and was installed using an internal app sharing URL. Follow the Play Console instructions to share your app internally.
In-app updates is a Google Play Core libraries feature that prompts active users to update your app. The in-app updates feature is supported on devices running Android 5.0 (API level 21) or higher. Additionally, in-app updates are only supported for Android mobile devices, Android tablets, and Chrome OS devices.
There is no way to set the update's priority through the Google Play Console; instead, you must use the Google Play Developer API.
Contrary to other answers that say that test build must be in release mode or has to be uploaded to Play Console Test track - that is all wrong, nowhere in the documentation there is any mention of any of that.
If you meet requirements API >= 21 && have internet connection and face this issue, do the following to resolve:
It seems like a caching issue with PlayStore and above steps refresh it. After that you'll be able to test In App Updates even in debug mode.
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