重现此错误的步骤:
- 单击更新按钮并打开更新应用程序对话框,因为它是
AppUpdateType.FLEXIBLE
. - 点击
No, thanks
- 再次尝试更新。应用程序崩溃并出现以下错误:
我在下一行通过 inappupdate 更新应用程序时遇到此异常。
appUpdateManager?.startUpdateFlowForResult(it, AppUpdateType.FLEXIBLE, activity, REQUEST_CODE_FLEXI_UPDATE) //it == AppUpdateInfo object
堆栈跟踪:
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:451)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
Caused by: android.content.IntentSender$SendIntentException
at android.app.Activity.startIntentSenderForResultInner(Activity.java:4878)
at android.app.Activity.startIntentSenderForResult(Activity.java:4847)
at androidx.fragment.app.FragmentActivity.startIntentSenderForResult(FragmentActivity.java:796)
at android.app.Activity.startIntentSenderForResult(Activity.java:4814)
at androidx.fragment.app.FragmentActivity.startIntentSenderForResult(FragmentActivity.java:781)
at com.google.android.play.core.appupdate.b.startUpdateFlowForResult(Unknown Source:22)
at newProfile.NewProfileFragment.startForInAppUpdate(NewProfileFragment.kt:752)
at newProfile.NewProfileFragment.access$startForInAppUpdate(NewProfileFragment.kt:60)
at newProfile.NewProfileFragment$setupAppUpdate$3.onClick(NewProfileFragment.kt:682)
at android.view.View.performClick(View.java:6935)
at android.widget.TextView.performClick(TextView.java:12752)
at android.view.View$PerformClick.run(View.java:26214)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
细节:
Android 版本:8.0
手机:三星 J7
更新
根据文档,
startUpdateFlowForResult
应该只调用一次AppUpdateInfo
实例。要再次调用,您必须创建AppUpdateInfo
实例。
但由于它的实例取决于以下条件,如何确保它的实例在调用之前是新创建的startUpdateFlowForResult
appUpdateManager?.appUpdateInfo?.addOnSuccessListener {
if (it.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE &&
it.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) {
appUpdateInfo = it
updateAvailable.value = true
} else {
updateAvailable.value = false
}
}
另外如何获取正在下载的应用程序的进度值,在文档中找不到。就我而言, onActivityResult 一直在调用,但哪个键给出了进度值?
还面临不同用例的另一个问题:跳过安装后 inappupdate 不可用