Android通讯录操作

来源:互联网 发布:windows ce最新版本 编辑:程序博客网 时间:2024/04/30 12:07
  /**   * 根据姓名删除联系人   *    * @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();    }  }

0 0