Phone Number Hint API not working on Android 12

Viewed 54

I am using the latest Phone Number Hint API library, provided by Google Play Services, for requesting phone number as hint. Here is my code :

implementation 'com.google.android.gms:play-services-auth:20.3.0'
implementation 'com.google.android.gms:play-services-auth-api-phone:18.0.1'

private val phoneNumberHintIntentResultLauncher =
    registerForActivityResult(ActivityResultContracts.StartIntentSenderForResult()) { result ->
        try {
            val phoneNumber =
                Identity.getSignInClient(requireContext()).getPhoneNumberFromIntent(result.data)
            Log.d("PhoneNumberRetrieved", phoneNumber)
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }


private fun requestPhoneNumberHint() {
    val request = GetPhoneNumberHintIntentRequest.builder().build()
    Identity.getSignInClient(requireContext())
        .getPhoneNumberHintIntent(request)
        .addOnSuccessListener { taskResult ->
            phoneNumberHintIntentResultLauncher.launch(
                IntentSenderRequest.Builder(
                    taskResult.intentSender
                ).build()
            )
        }
        .addOnFailureListener {
            it.printStackTrace()
        }
}

Above code is working fine on devices with Android version less than 12. But it is not working properly on devices with Android 12. I have tried on two different devices and here are the results*:

  1. Realme narzo 50a** - failureListner is invoked with this message 16: API is disabled
  2. Samsung Galaxy M32 - failureListner is invoked with this message 16: No phone number is found on this device. Even though the device has valid numbers available.

* NOTE : The old deprecated Hint Request API is working properly on both devices giving expected results i.e. showing device phone numbers in a pop-up.

** IMPORTANT : Same code worked properly on this device on day 1 of my implementation i.e. it showed the available phone numbers on a bottom sheet. But on the next day, for unknown reasons, it started giving above mentioned result. Although I made no changes in my code.

If anyone else has faced this issue or have any information regarding this, please do share you thoughts.

0 Answers
Related