How to get an icon associated with specific Account from AccountManager.getAccounts()

让人想犯罪 __ 提交于 2020-01-01 08:35:22

问题


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:


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;
    }


来源:https://stackoverflow.com/questions/10657096/how-to-get-an-icon-associated-with-specific-account-from-accountmanager-getaccou

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!