18

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.

Prags
  • 2,457
  • 2
  • 21
  • 38
sbaar
  • 1,429
  • 1
  • 17
  • 33
  • Which manufacturer and carrier is the device you are testing with? There are some problems reading the phone number for certain devices. – Steven Oct 24 '17 at 00:39
  • @StevenSoneff A nexus 6 sprint. But I can get the phone number/ country code with with simManager.getRawPhoneNumber(). thanks for the quick response. – sbaar Oct 24 '17 at 00:44
  • @StevenSoneff Restarting the phone did not work but erasing the play services local data caused it to start working. Hopefully this is just a cache issue from it being a new service? I'm reluctant to use the feature if it displays a spinner then disappears. I'd rather it just fail silently then confuse the user. – sbaar Oct 24 '17 at 01:34
  • On behalf of Kai Jung - I have exactly same problem. Did you solve the issue? Or is there any update on this? Clearing data from Play Service does not help. Samsung galaxy s6, s7 have this problem and only work on nexus 5x. – WhatsThePoint Nov 27 '17 at 10:02
  • I'm getting the same error on my brand new pixel 2 xl. And even on an oreo emulator, when normally accessing the sim from the emulator gives a phone number. Any idea when this will be fixed @StevenSoneff – sbaar Dec 05 '17 at 02:51
  • I have implemented this feature, check this out, Might help you. https://stackoverflow.com/a/52975789/8446183 – Akshay Kumar Both Oct 24 '18 at 18:35

2 Answers2

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.

Mohit Singh
  • 177
  • 2
  • 9
11

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.

Prags
  • 2,457
  • 2
  • 21
  • 38
acbelter
  • 447
  • 5
  • 10