androidandroid-jetpack-composeactivityresultcontracts

Picking contact from contacts list not working on some devices (Jetpack compose)


On some android devices after selecting contact I am getting RESULT_CANCELED and intent == null. Here is my code:

 val contactLauncher = rememberLauncherForActivityResult(object : ActivityResultContract<Int?, Uri?>() {
    override fun parseResult(resultCode: Int, intent: Intent?): Uri? {
        return if (resultCode == Activity.RESULT_OK) intent?.data else null
    }

    override fun createIntent(context: Context, input: Int?): Intent =
        Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI).also {
            it.type = ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE
        }
}) { uri ->
    ...
}

...
contactLauncher.launch(null)

I have also manually asked for contact read permission.

> Doesn`t work on Pixel 8a(Android 15), Pixel 5a(Android 14), Xiaomi Poco C40(Android 14) 

> Works on Pixel 8a(Android 15-virtual device), Honor x8a(Android 14), Samsung Galaxy A55(Android 14)

Solution

  • The reason was that launchMode was set to singleInstance, after changing to singleTask everything worked.