您的位置:首页 > 移动开发 > Android开发

Android通讯录操作

2015-06-08 10:47 531 查看
/**
* 根据姓名删除联系人
*
* @param name 联系人姓名
* @throws Exception
*/
public void delete(String name) throws Exception {
ContentResolver resolver = context.getContentResolver();
Cursor cursor =
resolver.query(RawContacts.CONTENT_URI, new String[] {Data._ID},
Data.DISPLAY_NAME + "=?", new String[] {name}, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
int id = cursor.getInt(0);
resolver.delete(RawContacts.CONTENT_URI, Data.DISPLAY_NAME + "=?",
new String[] {name});
resolver.delete(ContactsContract.Data.CONTENT_URI, Data.RAW_CONTACT_ID
+ "=?", new String[] {id + ""});
}
cursor.close();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息