Home > Mobile >  How to launch ActivityResultLauncher for picking contact?
How to launch ActivityResultLauncher for picking contact?

Time:09-10

I need to get contact info from activity which is out of my app. I read doc and try getting info as doc says. I can't understand what argument I must pass to launch method of ActivityResultLauncher.

private val getContact = registerForActivityResult(
    ActivityResultContracts.PickContact()
) { uri: Uri? ->
    Log.d(TAG, uri.toString())
}

....

button.setOnClickListener {
    getContact.launch() // here launch requires argument of type Void?
}

CodePudding user response:

You can pass in null or use the extension method from activity-ktx specifically for ActivityResultLauncher<Void?> that means you don't need to pass anything at all:

import androidx.activity.result.launch
  • Related