I am trying to select media from public storage using ActivityResultAPI
but it never ever triggers the callback function.
It was working perfectly fine until I move the compileSdkVersion
and targetSdkVersion
to 33.
Here is the ActivityResultLauncher
private var fileChooserLauncher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
Log.i(TAG, "registerForActivityResult: ${it}")
}
And here is how I am launching this:
val contentSelectionIntent = Intent(Intent.ACTION_GET_CONTENT)
contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE)
contentSelectionIntent.type = "image/*"
val chooserIntent = Intent(Intent.ACTION_CHOOSER)
chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent)
fileChooserLauncher.launch(chooserIntent)
Things I already tried but didn't work
- Getting
READ_MEDIA_IMAGES
permission - Adding/removing
android:alwaysRetainTaskState="true"
from Activity inAndroidManifest.xml
- Adding/removing
android:exported="true"
from Activity inAndroidManifest.xml
- Testing on Real Devices
- Testing different contracts such as
GetContent()
My build.gradle
app level contains the following libraries and more
implementation("androidx.activity:activity-ktx:1.6.1")
implementation("androidx.fragment:fragment-ktx:1.5.5")
Please help me out on this if you encountered something similar.
Thank you