Android, InstallException occurs when I use in-app

2020-03-31 02:49发布

问题:

In Google I/O 2019, In-app update is added newly.

So I am trying to use it following the document: https://developer.android.com/guide/app-bundle/in-app-updates

But it sent an InstallException like:

com.google.android.play.core.tasks.RuntimeExecutionException: com.google.android.play.core.install.InstallException: Install Error: -6
    at com.google.android.play.core.tasks.k.getResult(Unknown Source:18)
    at com.eastriver.workingtimer.ui.MainActivity$onCreate$1.onComplete(MainActivity.kt:35)

And my code is here:

val appUpdateManager = AppUpdateManagerFactory.create(this)
val appUpdateInfo = appUpdateManager.appUpdateInfo
appUpdateInfo.addOnCompleteListener {
    val result = it.result
    if (result.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
                    && result.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) {

        info("should show update")
        appUpdateManager.startUpdateFlowForResult(
            result,
            AppUpdateType.FLEXIBLE,
            this,
            1)
    } else {
        info("This is already latest version!")
    }
}

I know, it is released just nowadays. But somebody knows this?

回答1:

The error codes are documented in the javadoc.

This says:

int ERROR_INSTALL_NOT_ALLOWED

The download/install is not allowed, due to the current device state (e.g. low battery, low disk space, ...).

Constant Value: -6 (0xfffffffa)

So I suspect your device either does not have space or is not plugged in to power, and the update preferences on this device require power and WiFi.