9

Steps to reproduce this error:

  1. Click update button & it opens update app dialog since it's AppUpdateType.FLEXIBLE.
  2. Click No, thanks
  3. Try update again. App crashes with following error:

I'm getting this exception while updating the app via inappupdate on following line.

appUpdateManager?.startUpdateFlowForResult(it, AppUpdateType.FLEXIBLE, activity, REQUEST_CODE_FLEXI_UPDATE) //it == AppUpdateInfo object

Stacktrace:

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)

Details:

Android version: 8.0
Phone: Samsung J7

Update

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

but since its instance depends on below condition, how to make sure its instance newly gets created before calling startUpdateFlowForResult

 appUpdateManager?.appUpdateInfo?.addOnSuccessListener {
            if (it.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE &&
                    it.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) {
                appUpdateInfo = it
                updateAvailable.value = true
            } else {
                updateAvailable.value = false
            }
        }

Also how to get progress value of app being downloaded, couldn't find it in documentation. In my case, onActivityResult keeps calling but which key gives progress value?

Also facing another issue with different use case: inappupdate not available after skipping installation

Bolt UIX
  • 5,988
  • 6
  • 31
  • 58
AskQ
  • 4,215
  • 7
  • 34
  • 61
  • The documentation of [`IntentSender.SendIntentException`](https://developer.android.com/reference/android/content/IntentSender.SendIntentException) says: "_Exception thrown when trying to send through a PendingIntent that has been canceled or is otherwise no longer able to execute the request_". I'm not familiar enough with Android to be of much help, but maybe that documentation can help point you in the right direction. – Slaw Jul 31 '19 at 13:50
  • Yeah but its internal exception of Activity class which even can't be handled due to which app crashes. It shouldn't have appeared in first place. – AskQ Jul 31 '19 at 13:53
  • 1
    According to [this documentation](https://developer.android.com/guide/app-bundle/in-app-updates#start_update), you can only use an instance of `AppUpdateInfo` one time. Try using a new instance for the retry (if you aren't already). – Slaw Jul 31 '19 at 14:18
  • @Slaw@Slaw AppUpdateInfo gets initialized if following case: appUpdateManager?.appUpdateInfo?.addOnSuccessListener { if (it.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE && it.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) { appUpdateInfo = it updateAvailable.value = true } else { updateAvailable.value = false } } – AskQ Aug 01 '19 at 09:58
  • I have updated the question.. please check.. – AskQ Aug 01 '19 at 10:04
  • @AskQ, Did you find out solution to re-create AppUpdateInfo – Anukool srivastav Sep 16 '20 at 04:55
  • call this line.. it will newly initiate appUpdateInfo again.. appUpdateManager?.appUpdateInfo?.addOnSuccessListener { appUpdateInfo -> – AskQ Oct 01 '20 at 10:21

1 Answers1

12

The problem is that you are trying to trigger startUpdateFlowForResult with the same AppUpdateInfo twice.

As @Slaw suggested, after a failed or canceled update you need to do appUpdateManager.appUpdateInfo.addOnSuccessListener again in order to have another instance of AppUpdateInfo to make second call to startUpdateFlowForResult

marp
  • 464
  • 5
  • 9