How to get the Android device's primary e-mail address

后端 未结 12 2495
借酒劲吻你
借酒劲吻你 2020-11-21 13:30

How do you get the Android\'s primary e-mail address (or a list of e-mail addresses)?

It\'s my understanding that on OS 2.0+ there\'s support for multiple e-mail add

12条回答
  •  Happy的楠姐
    2020-11-21 13:42

    There is an Android api that allows the user to select their email address without the need for a permission. Take a look at: https://developers.google.com/identity/smartlock-passwords/android/retrieve-hints

    HintRequest hintRequest = new HintRequest.Builder()
            .setHintPickerConfig(new CredentialPickerConfig.Builder()
                    .setShowCancelButton(true)
                    .build())
            .setEmailAddressIdentifierSupported(true)
            .setAccountTypes(IdentityProviders.GOOGLE)
            .build();
    
    PendingIntent intent = mCredentialsClient.getHintPickerIntent(hintRequest);
    try {
        startIntentSenderForResult(intent.getIntentSender(), RC_HINT, null, 0, 0, 0);
    } catch (IntentSender.SendIntentException e) {
        Log.e(TAG, "Could not start hint picker Intent", e);
    }
    

    This will show a picker where the user can select an emailaddress. The result will be delivered in onActivityResult()

提交回复
热议问题