I am building a custom capacitor plugin to fetch the user's phone numbers. I am using capacitor 3 with Ionic 6.
I found a solution which is not deprecated and is a lot recent to fetch the user's phone numbers.
here is my code to get the phone number -
private void requestHint() {
HintRequest hintRequest = new HintRequest.Builder()
.setPhoneNumberIdentifierSupported(true)
.build();
PendingIntent intent = Credentials.getClient(getActivity()).getHintPickerIntent(hintRequest);
IntentSenderRequest.Builder intentSenderRequest = new IntentSenderRequest.Builder(intent.getIntentSender());
hintLauncher.launch(intentSenderRequest.build());
}
ActivityResultLauncher<IntentSenderRequest> hintLauncher = registerForActivityResult(new ActivityResultContracts.StartIntentSenderForResult(),
result -> {
if(result!=null && result.getData()!=null){
Intent data = result.getData();
Credential credential = data.getParcelableExtra(Credential.EXTRA_KEY);
String phoneNum = credential.getId();
}
});
But I am running across an error on Android Studio "Cannot resolve method 'registerForActivityResult' in 'NumberPluginPlugin'"
What am I missing here? As suggested by some folks online I have added the following dependencies -
implementation "androidx.fragment:fragment:1.4.1"
implementation "androidx.activity:activity:1.4.0"
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
Still I am not sure what is going wrong here.