Am trying to use GoogleApiClient to implement Automatic SMS Verification Android in a fragment. Am following the official documentation here Automatic SMS Verification with the SMS Retriever API
Am stuck in this part Obtaining user phone number
Below is my code and how i have been trying to implement in Android using a fragment where i have an edit text of TextInputEditText for the phone number
My Fragment declarations
TextInputEditText etOtpPhoneNumber;
GoogleApiClient googleApiClient;
private static final int RESOLVE_HINT = 1;
My Fragment implements the following
public class smsRetriever extends Fragment implements GoogleApiClient.OnConnectionFailedListener,
GoogleApiClient.ConnectionCallbacks
Finding my views in xml and initializing GoogleApiClient
etOtpPhoneNumber = view.findViewById(R.id.et_otp_phone_number);
googleApiClient = new GoogleApiClient.Builder(requireActivity())
.addConnectionCallbacks(this)
.enableAutoManage(requireActivity(), this)
.addApi(Auth.CREDENTIALS_API)
.build();
My methods
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
}
@Override
public void onConnected(@Nullable Bundle bundle) {
}
@Override
public void onConnectionSuspended(int i) {
}
// Obtain the phone number from the result
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESOLVE_HINT) {
if (resultCode == RESULT_OK) {
Credential credential = data.getParcelableExtra(Credential.EXTRA_KEY);
// credential.getId(); <-- will need to process phone number string
}
}
}
I am implementing the following method to obtain users phone number which am having a problem with
private void requestPhoneNumberHint() {
HintRequest hintRequest = new HintRequest.Builder()
.setPhoneNumberIdentifierSupported(true)
.build();
PendingIntent intent = Auth.CredentialsApi.getHintPickerIntent(
googleApiClient, hintRequest);
try {
startIntentSenderForResult(intent.getIntentSender(),
RESOLVE_HINT, null, 0, 0, 0);
}catch (IntentSender.SendIntentException e){
e.printStackTrace();
}
}
The problem is with startIntentSenderForResult where i am having the below error
Expected 7 arguments but found 6
According to startIntentSenderForResult method is should implement the following
public void startIntentSenderForResult(@SuppressLint("UnknownNullness") IntentSender intent,
int requestCode, @Nullable Intent fillInIntent, int flagsMask, int flagsValues,
int extraFlags, @Nullable Bundle options)
What should i put for @Nullable Bundle options
startIntentSenderForResult(pendingIntent.getIntentSender(), CREDENTIAL_PICKER_REQUEST, null,
0, 0, 0, new Bundle());
or
startIntentSenderForResult(intent.getIntentSender(),
RESOLVE_HINT, null, 0, 0, 0, null);