Reputation: 1
I am working on Ionic
5 POC to get the user phone number. Can someone help me to implement "Obtain the user's phone number" in the angular
code?
Reference: link here
I tried to find Cordova / capacitor plugin but there is no plugin found that help to make hint request to get the phone number. If anyone can convert that code into angular, will be highly appreciated.
Upvotes: 0
Views: 759
Reputation: 215
From the following code, in the if (resultCode == RESULT_OK && data!=null)
block you need to get the phone number in the variable credential
, here I am setting the phone number in a textfield userMobileNo
you can do any other operation as per your requirement.
And in the else
part when no hints are available you can request focus on the textfield where the user has to enter the mobile number.
Note: I have written the code in Kotlin but it will be automatically generated into Java in Android Studio
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESOLVE_HINT) {
if (resultCode == RESULT_OK && data!=null) {
val credential = data.getParcelableExtra<Credential>(Credential.EXTRA_KEY)
userMobileNo.setText(credential?.id?.substring(3))
}
else if (resultCode == CredentialsApi.ACTIVITY_RESULT_NO_HINTS_AVAILABLE) {
//if no hints available
}
}
Upvotes: 0