需要使用Android中的单个光标从内容提供者获取联系人帐户名称和联系人显示名称
问题描述:
我需要列出属于单个帐户的所有联系人的“显示名称”。需要使用Android中的单个光标从内容提供者获取联系人帐户名称和联系人显示名称
我打算使用游标适配器来填充列表,因此需要在单个内容提供者查询中提取相应的字段(显示名称,帐户信息)。
查看联系人数据库结构原始联系人,联系人和数据中的单个表将无法提供这两个参数,因此联接是必要的。
据我所知,连接将不可能从内容提供者获取数据。
您能否让我知道问题的解决方案?
在此先感谢。
答
您可以在ContactsContract.RawContacts上选择您的帐户名称,然后在ContactsContract.RawContacts.data表上选择MIME类型CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE
。
+0
感谢dco maeglin给你的输入。但我需要使用一个单一的光标,我不会为ContactsContract.RawContacts,ContactsContract.RawContacts.data :( – 2010-11-25 17:56:46
答
下面是代码(这将填补CUR2所有在帐户每个联系人的姓名信息[0]。名称这仅仅是该帐户的字符串名称,它会按名字排序的话):
cur2 = getContentResolver().query(Data.CONTENT_URI, DataQuery.PROJECTION, DataQuery.SELECTION, new String[] {accounts[0].name}, DataQuery.COLUMN_GIVEN_NAME + " ASC");
private interface DataQuery {
public static final String[] PROJECTION =
new String[] {Data._ID, Data.MIMETYPE, Data.DATA1, Data.DATA2,
Data.DATA3, Data.DATA4, Data.DATA5, Data.DATA6, Data.DATA7,
Data.DATA8, Data.DATA9, Data.DATA10, Data.DATA11, Data.DATA12,
Data.DATA13, Data.DATA14, Data.DATA15, ContactsContract.RawContacts.ACCOUNT_NAME };
public static final int COLUMN_ID = 0;
public static final int COLUMN_MIMETYPE = 1;
public static final int COLUMN_DATA1 = 2;
public static final int COLUMN_DATA2 = 3;
public static final int COLUMN_DATA3 = 4;
public static final int COLUMN_DATA4 = 5;
public static final int COLUMN_DATA5 = 6;
public static final int COLUMN_DATA6 = 7;
public static final int COLUMN_DATA7 = 8;
public static final int COLUMN_DATA8 = 9;
public static final int COLUMN_DATA9 = 10;
public static final int COLUMN_DATA10 = 11;
public static final int COLUMN_DATA11 = 12;
public static final int COLUMN_DATA12 = 13;
public static final int COLUMN_DATA13 = 14;
public static final int COLUMN_DATA14 = 15;
public static final int COLUMN_DATA15 = 16;
public static final int COLUMN_PHONE_NUMBER = COLUMN_DATA1;
public static final int COLUMN_PHONE_TYPE = COLUMN_DATA2;
public static final int COLUMN_EMAIL_ADDRESS = COLUMN_DATA1;
public static final int COLUMN_EMAIL_TYPE = COLUMN_DATA2;
public static final int COLUMN_GIVEN_NAME = COLUMN_DATA2;
public static final int COLUMN_MIDDLE_NAME = COLUMN_DATA5;
public static final int COLUMN_FAMILY_NAME = COLUMN_DATA3;
public static final int COLUMN_WEBSITE = COLUMN_DATA1;
public static final int COLUMN_ADDRESS_TYPE = COLUMN_DATA2;
public static final int COLUMN_STREET_ADDRESS = COLUMN_DATA4;
public static final int COLUMN_CITY_ADDRESS = COLUMN_DATA7;
public static final int COLUMN_STATE_ADDRESS = COLUMN_DATA8;
public static final int COLUMN_ZIP_ADDRESS = COLUMN_DATA9;
public static final int COLUMN_ORGANIZATION_NAME = COLUMN_DATA1;
public static final int COLUMN_TITLE = COLUMN_DATA4;
public static final int COLUMN_PHOTO = COLUMN_DATA15;
public static final int COLUMN_NOTES = COLUMN_DATA1;
public static final String SELECTION = ContactsContract.RawContacts.ACCOUNT_NAME + "=? and " + Data.MIMETYPE + "='vnd.android.cursor.item/name'";
//public static final String a = Data.
}
我想知道你是否曾经为此找到过解决方案。我有同样的问题,还没有找到答案。 – Chillie 2011-12-28 18:22:01