【问题标题】:How to get the account type name and icon for a contact list group?如何获取联系人列表组的帐户类型名称和图标?
【发布时间】:2014-10-10 19:09:10
【问题描述】:

我可以使用这段代码从 Android 的联系人提供程序中检索联系人组列表:

// Create a string array with the fields to retrieve for each group
final String[] groupsProjection = new String[] {
        ContactsContract.Groups._ID,
        ContactsContract.Groups.TITLE,
        ContactsContract.Groups.ACCOUNT_NAME,
        ContactsContract.Groups.ACCOUNT_TYPE
        };

// Create a cursor for iterating over the groups
Cursor groupsCursor = context.getContentResolver().query(
        ContactsContract.Groups.CONTENT_URI,
        groupsProjection, null, null, null);

在检索时,我希望向用户显示组列表,并在结果旁边显示帐户类型的图标(例如,对于帐户类型 com.google,我希望显示 Google 的图标,Facebook 的 Facebook 帐户图标...)。

如何检索每种帐户类型的图标,最好不必添加 ACCOUNT_MANAGER 权限?

【问题讨论】:

    标签: java android


    【解决方案1】:
    if (groupsCursor .getCount() > 0) {
         while (groupsCursor .moveToNext()) 
                {
    
                 String  id = groupsCursor .getString(cur
                            .getColumnIndex(BaseColumns._ID));
    
                    String icon = groupsCursor 
                            .getString(cur
                                    .getColumnIndex(ContactsContract.Contacts.ICON));
                     //get more column values of each contact.
    
        }
    }
    

    【讨论】:

    • 即使有一个名为 ContactsContract.Contacts.ICON 的字段(但没有),我希望检索帐户的图标,而不是联系人的照片
    猜你喜欢
    • 2018-01-25
    • 1970-01-01
    • 2012-04-18
    • 2017-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-19
    相关资源
    最近更新 更多