18

当使用google 的短信检索器 api中的代码首先获取设备的电话号码时,对话框会显示一个加载微调器,然后很快消失。在 onActivityResult 中,resultCode 为 1002,intent 为空。不存在此错误代码的文档。我正在使用的确切代码是

        email.setOnClickListener(v -> {

        HintRequest hintRequest = new HintRequest.Builder().setHintPickerConfig(new CredentialPickerConfig.Builder().setPrompt(0).build())
                .setPhoneNumberIdentifierSupported(true)
                .setEmailAddressIdentifierSupported(false)
                //.setAccountTypes(IdentityProviders.GOOGLE)
                .build();

        PendingIntent intent =
                Auth.CredentialsApi.getHintPickerIntent(mGoogleApiClient, hintRequest);
        try {
            startIntentSenderForResult(intent.getIntentSender(),599,null,0,0,0,null);
        } catch (IntentSender.SendIntentException e) {
            Log.e("create", "Could not start hint picker Intent", e);
        }
    });


    mGoogleApiClient =  new GoogleApiClient.Builder(getContext())
            .enableAutoManage(getActivity(),connectionResult -> {
                Timber.e("conenction failed");
            })
            .addApi(Auth.CREDENTIALS_API)
            .addApi(Auth.GOOGLE_SIGN_IN_API)
            .build();

如果我设置为 true EmailAddressIdentifiedSupported 或什至只是取消注释 setAccountTypes,那么提示请求将正确显示电子邮件帐户并将名称和电子邮件返回到应用程序,但启用两者不会导致凭据 ID 成为电话号码,如1

这是从片段调用的,但是从任何位置调用各种 startIntentSenderForResult 都没有区别。

4

2 回答 2

13

The HintRequest api provided by google has not fully accomplished its feature and is quite buggy , Its works fine in google devices as said by developers "OEM issue that their pixel or nexus phone working well."

https://issuetracker.google.com/issues/77884951 .

https://github.com/googlesamples/android-credentials/issues/27

Many apps are still using it with handling the exceptional cases with own logic such as myntra verify number feature which is there on the profile page.

于 2018-12-04T06:38:09.127 回答
11

resultCode = 1002 表示ACTIVITY_RESULT_NO_HINTS_AVAILABLE(表示没有可用提示的活动结果代码)

API 参考文档 > CredentialsApi

要仅通过电话显示提示,请尝试仅使用setPhoneNumberIdentifierSupported(true)

HintRequest hintRequest = new HintRequest.Builder()
.setPhoneNumberIdentifierSupported(true)
.build();

还尝试在具有其他帐户的设备上进行测试。

于 2018-03-22T14:24:52.733 回答