android联系人群组操作

来源:互联网 发布:贵州大数据产业规划 编辑:程序博客网 时间:2024/04/30 06:07

android联系人群组操作


查询群组

Cursor cursor = getContentResolver().query(Groups.CONTENT_URI,null,null,null,null);   
for (cursorAll.moveToFirst();!(cursorAll.isAfterLast());cursorAll.moveToNext()) {   
组名:cursor.getString(cursor.getColumnIndex(Groups.TITLE));   
组id:curso.getLong(cursor.getColumnIndex(Groups._ID));   
}   
  
新建组(名字为name):   
    ContentValues values = new ContentValues();   
   values.put(Groups.TITLE, name);   
    getContentResolver().inser(Groups.CONTENT_URI, values);   
  
删除组(Id为groupId):   
    getContentResolver().delete(Uri.parse(Groups.CONTENT_URI +"?" +ContactsContract.CALLER_IS_SYNCADAPTER + "=true"),Groups._ID+"="+groupId,null);   
  
给组重命名(oldName;newName;groupId):   
Uri uri = ContentUris.withAppendedId(Groups.CONTENT_URI, groupId);   
ContentValues values = new ContentValues();   
values.put(Groups.TITLE,newName);   
getContentResolver().update(uri,values,null,null);   
  
给组添加成员(groupId,personId):   
ContentValues values = new ContentValues();         
values.put(ContactsContract.CommonDataKinds.GroupMembership.RAW_CONTACT_ID,personId);         
values.put(ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID,groupId);         
values.put(ContactsContract.CommonDataKinds.GroupMembership.MIMETYPE,ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE);           
getContentResolver().insert(ContactsContract.Data.CONTENT_URI, values);   
  
给组移除成员(groupId,personId):   
getContentResolver().delete(ContactsContract.Data.CONTENT_URI,ContactsContract.CommonDataKinds.GroupMembership.RAW_CONTACT_ID + "=? and " +ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID + "=? and " +ContactsContract.CommonDataKinds.GroupMembership.MIMETYPE + "=?",new String[]{"" + personId,"" + groupId,ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE}); 
原创粉丝点击