0

我正在尝试使用 GoogleApiClient 在片段中实现自动短信验证 Android。我正在关注此处的官方文档Automatic SMS Verification with the SMS Retriever API

我卡在这部分获取用户电话号码

下面是我的代码以及我如何尝试在 Android 中使用一个片段来实现,其中我有一个 TextInputEditText 的编辑文本作为电话号码

我的片段声明

    TextInputEditText etOtpPhoneNumber;

    GoogleApiClient googleApiClient;

    private static final int RESOLVE_HINT = 1;

我的片段实现了以下

public class smsRetriever extends Fragment implements GoogleApiClient.OnConnectionFailedListener,
        GoogleApiClient.ConnectionCallbacks

在 xml 中查找我的视图并初始化 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();

我的方法

    @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
            }
        }
    }

我正在实施以下方法来获取有问题的用户电话号码


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();

        }

    }

问题出在 startIntentSenderForResult 我有以下错误

Expected 7 arguments but found 6

根据 startIntentSenderForResult 方法是应该实现以下

public void startIntentSenderForResult(@SuppressLint("UnknownNullness") IntentSender intent,
            int requestCode, @Nullable Intent fillInIntent, int flagsMask, int flagsValues,
            int extraFlags, @Nullable Bundle options)

我应该为@Nullable Bundle 选项添加什么

4

1 回答 1

0

startIntentSenderForResult(pendingIntent.getIntentSender(), CREDENTIAL_PICKER_REQUEST, null,
                    0, 0, 0, new Bundle());

或者


startIntentSenderForResult(intent.getIntentSender(),
                    RESOLVE_HINT, null, 0, 0, 0, null);

于 2021-01-03T03:37:59.393 回答