Play Services Hint Request cannot display phone numbers when requested

二次信任 提交于 2019-12-03 11:58:55

问题


When using the code from google's sms retriever api to first grab the device's phone number, the dialog is shown with a loading spinner, then quickly disappears. In onActivityResult, the resultCode is 1002 and the intent is empty. No documentation for this error code exists. The exact code I'm using is

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

If I were to set as true EmailAddressIdentifiedSupported OR even just uncomment setAccountTypes, then the hint request would function correctly showing email accounts and returning the name and email to the app, but enabling both does not cause the credential id to be the phone number as in 1

This is being called from a fragment, but calling every variety of startIntentSenderForResult from any location makes no difference.


回答1:


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.




回答2:


resultCode = 1002 means ACTIVITY_RESULT_NO_HINTS_AVAILABLE (Activity result code indicating that there were no hints available)

API Reference Doc > CredentialsApi

To display hints only by phone try to use only setPhoneNumberIdentifierSupported(true):

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

Also try to test on devices with other accounts.



来源:https://stackoverflow.com/questions/46900310/play-services-hint-request-cannot-display-phone-numbers-when-requested

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!