Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@Composable
fun PhoneNumberConsent(
onPhoneNumberFetchedFromDevice: (phoneNumber: String) -> Unit,
) {
val context = LocalContext.current
val getPhoneNumberConsent =
rememberLauncherForActivityResult(ActivityResultContracts.StartIntentSenderForResult()) { result: ActivityResult? ->
if (result?.resultCode == Activity.RESULT_OK && result.data != null) {
val credential = result.data!!.getParcelableExtra<Credential>(Credential.EXTRA_KEY)
if (credential != null) {
Timber.d("Phone number fetched from auto fill")
onPhoneNumberFetchedFromDevice(credential.id)
}
} else {
Timber.d("No number selected or unavailable. User can type manually.")
}
}
LaunchedEffect(Unit) {
val credentialsClient = Credentials.getClient(context)
val hintRequest = HintRequest.Builder()
.setPhoneNumberIdentifierSupported(true)
.build()
val intent = credentialsClient.getHintPickerIntent(hintRequest)
getPhoneNumberConsent.launch(IntentSenderRequest.Builder(intent.intentSender).build())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment