java.lang.reflect.InvocationTargetException while inappupdate android 如果重试

java.lang.reflect.InvocationTargetException while inappupdate android if retries

重现此错误的步骤:

  1. 点击更新按钮,它会打开更新应用程序对话框,因为它是 AppUpdateType.FLEXIBLE
  2. 点击No, thanks
  3. 再次尝试更新。应用程序崩溃并出现以下错误:

我在通过下一行的 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.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
Phone:三星 J7

更新

As per documentation, startUpdateFlowForResult should only called for once AppUpdateInfo instance. For calling again, you must create AppUpdateInfo instance.

但由于它的实例取决于以下条件,如何确保在调用之前新创建它的实例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 not available after skipping installation

问题是您试图用相同的 AppUpdateInfo 触发 startUpdateFlowForResult 两次。

正如@Slaw 所建议的,在更新失败或取消后,您需要再次执行 appUpdateManager.appUpdateInfo.addOnSuccessListener 以便让 AppUpdateInfo 的另一个实例再次调用 startUpdateFlowForResult