Last active
September 14, 2021 14:23
-
-
Save rahulsainani/7fb27aadabbcd222243e1fc0fec183d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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