现在还没有成功,我的想法是ContentResolver contentresolver=getContentResolver();
Cursor cursor=contentresolver.query(RawContacts.CONTENT_URI,null, null, null, null);
while(cursor.moveToNext()){
long contactid = cursor.getLong(cursor.getColumnIndex(RawContacts._ID));
contentresolver.delete(RawContacts.CONTENT_URI, "Data.RAW_CONTACT_ID="+contactid, null);
}
大致就是通过Uri查询,然后用cursor得到具体的匹配条件,然后在用delete中的第二个参数决定删除特定的联系人,但是不成功,代码有问题,请教如何改正啊?急……

解决方案 »

  1.   

    这么改应该可以了
    String where = ContactsContract.Data._ID  + " =?";
        String[] whereparams = new String[]{rawId};
    //content.delete(RawContacts.CONTENT_URI, where, whereparams);
    long id = Long.parseLong(rawId);
    //content.delete(ContentUris.withAppendedId(RawContacts.CONTENT_URI, id), null, null);
    content.delete(ContactsContract.RawContacts.CONTENT_URI, where, whereparams);
      

  2.   

    楼主那样用会报错
    contentresolver.delete(RawContacts.CONTENT_URI, "Data.RAW_CONTACT_ID="+contactid, null);应改成
    String where = ContactsContract.Data._ID + " =?";
    String rawId = cursor.getString(cursor.getColumnIndex(RawContacts._ID));
    String[] whereparams = new String[]{rawId};
    contentresolver.delete(ContactsContract.RawContacts.CONTENT_URI, where, whereparams);
      

  3.   

    试一试先保存 cursor 中的数据,关闭 cursor 之后,再进行删除?