-->

Play Services Hint Request cannot display phone nu

2019-03-25 17:01发布

问题:

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:

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.



回答2:

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.