admin管理员组

文章数量:1301502

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)

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)
Share Improve this question edited Feb 11 at 11:09 Mery Karapetyan asked Feb 11 at 8:41 Mery KarapetyanMery Karapetyan 2012 silver badges8 bronze badges 1
  • Please edit the question to add what kind of devices this doesn't work for. Is it a specific API level, is it a specific manufacturer or something else? How can the issue be reproduced? – tyg Commented Feb 11 at 9:01
Add a comment  | 

1 Answer 1

Reset to default 0

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

本文标签: androidPicking contact from contacts list not working on some devices (Jetpack compose)Stack Overflow