Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In App Update API always returns 1 (UPDATE_NOT_AVAILABLE)

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.

  • Sign apk with the same package name.
  • Clear Playstore apk cache and storage.
  • Download apk from playstore and uninstall it from device. then after downgrade version code and sign apk and install it in device. Still not showing update app dialog.
like image 693
Mehul Kabaria Avatar asked Jul 03 '19 05:07

Mehul Kabaria


People also ask

How to test InApp update Android?

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.

What is in-app update?

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.

How do I change priority on Play Store console?

There is no way to set the update's priority through the Google Play Console; instead, you must use the Google Play Developer API.


1 Answers

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:

  • Confirm that your test build has lower version code than what's in production
  • Clear Storage & Cache for PlayStore app
  • Open play store using account that has previously downloaded the app
  • Navigate to your app listing in PlayStore and confirm that "Update" button is showing.

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.

like image 130
AlexVPerl Avatar answered Oct 11 '22 03:10

AlexVPerl