How to get an icon associated with specific Accoun

2019-04-05 13:58发布

There is an icon displayed in account settings for each account. For Google account there is one icon, for Facebook another.

Is there a way of getting this icon from the code in application?

1条回答
何必那么认真
2楼-- · 2019-04-05 14:22

Finally, I solved it:

    private Drawable getIconForAccount(Account account, AccountManager manager) {
        AuthenticatorDescription[] descriptions =  manager.getAuthenticatorTypes();
        PackageManager pm = getContext().getPackageManager();
        for (AuthenticatorDescription description: descriptions) {
            if (description.type.equals(account.type)) {
                return pm.getDrawable(description.packageName, description.iconId, null); 
            }
        }
        return null;
    }
查看更多
登录 后发表回答