registerForActivityResult callback is not getting called

776 Views Asked by At

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

  1. Getting READ_MEDIA_IMAGES permission
  2. Adding/removing android:alwaysRetainTaskState="true" from Activity in AndroidManifest.xml
  3. Adding/removing android:exported="true" from Activity in AndroidManifest.xml
  4. Testing on Real Devices
  5. 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

0

There are 0 best solutions below