Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get user number using intent request not working?

I am justing trying to get phone number using GetPhoneNumberHintIntentRequest to replace HintRequest. So just trying to follow google developer doc https://developers.google.com/identity/phone-number-hint/android#kotlin_2. But after following doc I feel this doc is incomplete.

enter image description here

  val phoneNumberHintIntentResultLauncher: ActivityResultLauncher<Intent> =
    registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
        try {
            val phoneNumber = Identity.getSignInClient(requireActivity()).getPhoneNumberFromIntent(result.data)
        } catch(e: Exception) {
        }
  }

So as per doc you need to pass intent to phoneNumberHintIntentResultLauncher but there is no method inside GetPhoneNumberHintIntentRequest.

enter image description here

Even if you see doc then you realise that you need to replace signInClient to getSignInClient.

If any one know about above issue then let me know or any doc where I can achieve my goal.

like image 551
duggu Avatar asked Aug 12 '26 09:08

duggu


1 Answers

Have been facing this recently.

Please change the result launcher type as follows.

    val resultLauncher: ActivityResultLauncher<IntentSenderRequest> = registerForActivityResult(StartIntentSenderForResult()) { result ->
        try {
            val phoneNumber = Identity.getSignInClient(requireActivity()).getPhoneNumberFromIntent(result.data)
            // Do something with the number
        } catch (e: Exception) {
            Log.e(TAG, "Phone Number Hint failed")
        }

And launch the intent as

    ...
    .addOnSuccessListener { request: PendingIntent ->
            try {
                resultLauncher.launch(IntentSenderRequest.Builder(request).build())
            } catch(e: Exception) {
                Log.e(TAG, "Launching the PendingIntent failed")
            }
        }
    ...

The document is indeed incomplete as it seems.

like image 157
Haris Kumar Avatar answered Aug 14 '26 10:08

Haris Kumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!