Fixed
Status Update
Comments
jb...@google.com <jb...@google.com>
ap...@google.com <ap...@google.com> #2
Hi Ed, Thank you so much for these suggestions. I've been reviewing them and merging them in. Hopefully it should be live. I've included a thank you note too in the article.
ap...@google.com <ap...@google.com> #3
Great! Thanks a lot, I'll look for the live updates soon!
jb...@google.com <jb...@google.com> #4
This has been fixed internally and will be available in the Activity 1.2.0-alpha06 release.
To address this the ActivityResultLauncher
now gives access to the ActivityResultContract
.
With the contract, you can create the intent and use it to call resolveActivity()
directly:
launcher.contract.createIntent(context, input).resolveActivity(packageManager)
il...@google.com <il...@google.com> #5
Keep in mind that due to the resolveActivity()
will return null unless you add the specific <queries>
elements to your manifest.
As per that doc, the alternative is to catch the ActivityNotFoundException
yourself by wrapping your launch()
call in a try
/ catch
, just like if you were using startActivityForResult()
yourself.
Description
Component used: Activity Version used: 1.2.0-alpha04 Devices/Android versions reproduced on: Pixel 3 / Android 10
From the "Take photos" docs :
ActivityResultContracts.TakePicture
doesn't perform this check, so if there's no activity that can handle its intent, the app will crash. I'd guess this applies forTakePicturePreview
andTakeVideo
as well.I personally don't see an easy fix for this given the current API, and at the same time I wouldn't like to see the API getting more complicated to accommodate this. I'm currently happy using the simple
ActivityResultContracts.StartActivityForResult
so I can fully control the intent creation plus other relevant things like saving the file path properly so I don't lose it in case of process death.