您能否告诉我如何以编程方式获取联系人组
存储在我们的Android手机中?
最佳答案
final String[] GROUP_PROJECTION = new String[] {
ContactsContract.Groups._ID, ContactsContract.Groups.TITLE };
cursor = getContentResolver().query(
ContactsContract.Groups.CONTENT_URI, GROUP_PROJECTION, null,
null, ContactsContract.Groups.TITLE);
GlobalConfig.groupList.clear();
Group g = new Group();
g.GroupIdList += "0";
g.setGroupTitle("ALL");
GlobalConfig.groupList.add(g);
while (cursor.moveToNext()) {
String id = cursor.getString(cursor
.getColumnIndex(ContactsContract.Groups._ID));
String gTitle = (cursor.getString(cursor
.getColumnIndex(ContactsContract.Groups.TITLE)));
if (gTitle.contains("Group:")) {
gTitle = gTitle.substring(gTitle.indexOf("Group:") + 6).trim();
}
if (gTitle.contains("Favorite_")) {
gTitle = "Favorites";
}
if (gTitle.contains("Starred in Android")
|| gTitle.contains("My Contacts")) {
continue;
}
Group gObj = new Group();
int pos = GlobalConfig.GroupContainsTitle(gTitle);
if (pos != -1) {
gObj = GlobalConfig.groupList.get(pos);
gObj.GroupIdList += "," + id;
GlobalConfig.groupList.set(pos, gObj);
} else {
gObj.GroupIdList += id;
gObj.setGroupTitle(gTitle);
GlobalConfig.groupList.add(gObj);
}
// Log.d("GrpId Title", gObj.getGroupIdList() +
// gObj.getGroupTitle());
}