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

后端 未结 12 2310
借酒劲吻你
借酒劲吻你 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条回答
  •  旧巷少年郎
    2020-11-21 13:48

    I would use Android's AccountPicker, introduced in ICS.

    Intent googlePicker = AccountPicker.newChooseAccountIntent(null, null, new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE}, true, null, null, null, null);
    startActivityForResult(googlePicker, REQUEST_CODE);
    

    And then wait for the result:

    protected void onActivityResult(final int requestCode, final int resultCode,
                                    final Intent data) {
        if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
            String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
        }
    }
    

提交回复
热议问题