Pick an email using AccountPicker.newChooseAccountIntent

后端 未结 3 672
渐次进展
渐次进展 2020-12-04 20:30

I\'m trying to let the user pick an Email account using the following code:

Intent intent = AccountPicker.newChooseAccountIntent(null, null, new String[]{\"c         


        
3条回答
  •  鱼传尺愫
    2020-12-04 20:31

    According to the docs, the third parameter is allowableAccountTypes:

    allowableAccountTypes

    an optional string array of account types. These are used both to filter the shown accounts and to filter the list of account types that are shown when adding an account.

    For IMAP accounts in Email app that type is being returned as "com.google.android.legacyimap" (please do not log accounts' details in production):

    AccountManager accountManager = AccountManager.get(getApplicationContext());
    Account[] accounts = accountManager.getAccountsByType(null);
    for (Account account : accounts) {
        Log.d(TAG, "account: " + account.name + " : " + account.type);
    }
    

    That's using (add all account types you need to the array)

    Intent intent = AccountPicker.newChooseAccountIntent(null, null,
            new String[] {"com.google", "com.google.android.legacyimap"},
            false, null, null, null, null);
    

    is returning following on my device:

    Choose an account

    Please note that AccountPicker class is part of Google Play Services package, one could use AccountManager.newChooseAccountIntent() (added in API level 14) instead and get the same results.

    Hope this helps.

提交回复
热议问题