android.provider.ContactsContract.Contacts.Data Java Examples
The following examples show how to use
android.provider.ContactsContract.Contacts.Data.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContactsHelper.java From NonViewUtils with Apache License 2.0 | 8 votes |
/** * 修改联系人数据 */ public boolean update(String name, String phoneNumber) { try { //根据姓名求id,再根据id删除 Uri uri = Uri.parse("content://com.android.contacts/raw_contacts"); ContentResolver resolver = mContext.getContentResolver(); Cursor cursor = resolver.query(uri, new String[]{Data._ID}, "display_name=?", new String[]{name}, null); if (cursor.moveToFirst()) { int id = cursor.getInt(0); Uri mUri = Uri.parse("content://com.android.contacts/data");//对data表的所有数据操作 ContentResolver mResolver = mContext.getContentResolver(); ContentValues values = new ContentValues(); values.put("data1", phoneNumber); mResolver.update(mUri, values, "mimetype=? and raw_contact_id=?", new String[]{"vnd.android.cursor.item/phone_v2", id + ""}); return true; } } catch (Exception e) { e.printStackTrace(); } return false; }
Example #2
Source File: ContactsHelper.java From zone-sdk with MIT License | 6 votes |
/** * 删除单个数据,会直接删除是这个名字的人的所有信息 * * @param name 用户的姓名 * @return 是否删除成功 */ public boolean delete(String name) { try { //根据姓名求id Uri uri = Uri.parse("content://com.android.contacts/raw_contacts"); //查询到name=“name”的集合 Cursor cursor = mResolver.query(uri, new String[]{Data._ID}, "display_name=?", new String[]{name}, null); if (cursor.moveToFirst()) { int id = cursor.getInt(0); //根据id删除data中的相应数据 mResolver.delete(uri, "display_name=?", new String[]{name}); uri = Uri.parse("content://com.android.contacts/data"); mResolver.delete(uri, "raw_contact_id=?", new String[]{id + ""}); return true; } } catch (Exception e) { e.printStackTrace(); } return false; }
Example #3
Source File: ContactsHelper.java From zone-sdk with MIT License | 6 votes |
/** * 修改联系人数据 */ public boolean update(String name, String phoneNumber) { try { //根据姓名求id,再根据id删除 Uri uri = Uri.parse("content://com.android.contacts/raw_contacts"); Cursor cursor = mResolver.query(uri, new String[]{Data._ID}, "display_name=?", new String[]{name}, null); if (cursor.moveToFirst()) { int id = cursor.getInt(0); Uri mUri = Uri.parse("content://com.android.contacts/data");//对data表的所有数据操作 ContentValues values = new ContentValues(); values.put("data1", phoneNumber); mResolver.update(mUri, values, "mimetype=? and raw_contact_id=?", new String[]{"vnd.android.cursor.item/phone_v2", id + ""}); return true; } } catch (Exception e) { e.printStackTrace(); } return false; }
Example #4
Source File: ContactsHelper.java From NonViewUtils with Apache License 2.0 | 6 votes |
/** * 删除单个数据,会直接删除是这个名字的人的所有信息 * * @param name 用户的姓名 * @return 是否删除成功 */ public boolean delete(String name) { try { //根据姓名求id Uri uri = Uri.parse("content://com.android.contacts/raw_contacts"); ContentResolver resolver = mContext.getContentResolver(); //查询到name=“name”的集合 Cursor cursor = resolver.query(uri, new String[]{Data._ID}, "display_name=?", new String[]{name}, null); if (cursor.moveToFirst()) { int id = cursor.getInt(0); //根据id删除data中的相应数据 resolver.delete(uri, "display_name=?", new String[]{name}); uri = Uri.parse("content://com.android.contacts/data"); resolver.delete(uri, "raw_contact_id=?", new String[]{id + ""}); return true; } } catch (Exception e) { e.printStackTrace(); } return false; }
Example #5
Source File: CommonUtils.java From SmartChart with Apache License 2.0 | 5 votes |
/** * 往手机通讯录插入联系人 * * @param ct * @param name * @param tel * @param email */ public static void insertContact(Context ct, String name, String tel, String email) { ContentValues values = new ContentValues(); // 首先向RawContacts.CONTENT_URI执行一个空值插入,目的是获取系统返回的rawContactId Uri rawContactUri = ct.getContentResolver().insert(RawContacts.CONTENT_URI, values); long rawContactId = ContentUris.parseId(rawContactUri); // 往data表入姓名数据 if (!TextUtils.isEmpty(tel)) { values.clear(); values.put(Data.RAW_CONTACT_ID, rawContactId); values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);// 内容类型 values.put(StructuredName.GIVEN_NAME, name); ct.getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values); } // 往data表入电话数据 if (!TextUtils.isEmpty(tel)) { values.clear(); values.put(Data.RAW_CONTACT_ID, rawContactId); values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);// 内容类型 values.put(Phone.NUMBER, tel); values.put(Phone.TYPE, Phone.TYPE_MOBILE); ct.getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values); } // 往data表入Email数据 if (!TextUtils.isEmpty(email)) { values.clear(); values.put(Data.RAW_CONTACT_ID, rawContactId); values.put(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE);// 内容类型 values.put(Email.DATA, email); values.put(Email.TYPE, Email.TYPE_WORK); ct.getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values); } }
Example #6
Source File: ContactsHelper.java From AndroidBase with Apache License 2.0 | 5 votes |
/** * 添加一个联系人数据 * * @return 返回true表示添加成功,false表示失败 */ public boolean insert(String name, String phoneNumber) { //根据号码找数据,如果存在则不添加 if (getNameByPhoneNumber(phoneNumber) == null) { //插入raw_contacts表,并获取_id属性 Uri uri = Uri.parse("content://com.android.contacts/raw_contacts"); ContentResolver resolver = mContext.getContentResolver(); ContentValues values = new ContentValues(); long contact_id = ContentUris.parseId(resolver.insert(uri, values)); //插入data表 uri = Uri.parse("content://com.android.contacts/data"); //添加姓名 values.put("raw_contact_id", contact_id); values.put(Data.MIMETYPE, "vnd.android.cursor.item/name"); values.put("data2", name); resolver.insert(uri, values); values.clear(); //添加手机号码 values.put("raw_contact_id", contact_id); values.put(Data.MIMETYPE, "vnd.android.cursor.item/phone_v2"); values.put("data2", "2"); //2表示手机 values.put("data1", phoneNumber); resolver.insert(uri, values); values.clear(); return true; } else { return false; } }
Example #7
Source File: ContactsHelper.java From AndroidBase with Apache License 2.0 | 5 votes |
/** * 删除单个数据,会直接删除是这个名字的人的所有信息 * * @param name 用户的姓名 * @return 是否删除成功 */ public boolean delete(String name) { Cursor cursor = null; try { //根据姓名求id Uri uri = Uri.parse("content://com.android.contacts/raw_contacts"); ContentResolver resolver = mContext.getContentResolver(); //查询到name=“name”的集合 cursor = resolver.query(uri, new String[]{Data._ID}, "display_name=?", new String[]{name}, null); if (cursor != null) { if (cursor.moveToFirst()) { int id = cursor.getInt(0); //根据id删除data中的相应数据 resolver.delete(uri, "display_name=?", new String[]{name}); uri = Uri.parse("content://com.android.contacts/data"); resolver.delete(uri, "raw_contact_id=?", new String[]{id + ""}); return true; } } } catch (Exception e) { e.printStackTrace(); }finally { if (cursor != null) { cursor.close(); } } return false; }
Example #8
Source File: ContactsHelper.java From AndroidBase with Apache License 2.0 | 5 votes |
/** * 修改联系人数据 */ public boolean update(String name, String phoneNumber) { Cursor cursor = null; try { //根据姓名求id,再根据id删除 Uri uri = Uri.parse("content://com.android.contacts/raw_contacts"); ContentResolver resolver = mContext.getContentResolver(); cursor = resolver.query(uri, new String[]{Data._ID}, "display_name=?", new String[]{name}, null); if (cursor != null) { if (cursor.moveToFirst()) { int id = cursor.getInt(0); Uri mUri = Uri.parse("content://com.android.contacts/data");//对data表的所有数据操作 ContentResolver mResolver = mContext.getContentResolver(); ContentValues values = new ContentValues(); values.put("data1", phoneNumber); mResolver.update(mUri, values, "mimetype=? and raw_contact_id=?", new String[]{"vnd.android.cursor.item/phone_v2", id + ""}); return true; } } } catch (Exception e) { e.printStackTrace(); }finally { if (cursor != null) { cursor.close(); } } return false; }
Example #9
Source File: ContactsHelper.java From zone-sdk with MIT License | 5 votes |
/** * 添加一个联系人数据 * * @return 返回true表示添加成功,false表示失败 */ public boolean insert(String name, String phoneNumber) { //根据号码找数据,如果存在则不添加 if (getNameByPhoneNumber(phoneNumber) == null) { //插入raw_contacts表,并获取_id属性 Uri uri = Uri.parse("content://com.android.contacts/raw_contacts"); ContentValues values = new ContentValues(); long contact_id = ContentUris.parseId(mResolver.insert(uri, values)); //插入data表 uri = Uri.parse("content://com.android.contacts/data"); //添加姓名 values.put("raw_contact_id", contact_id); values.put(Data.MIMETYPE, "vnd.android.cursor.item/name"); values.put("data2", name); mResolver.insert(uri, values); values.clear(); //添加手机号码 values.put("raw_contact_id", contact_id); values.put(Data.MIMETYPE, "vnd.android.cursor.item/phone_v2"); values.put("data2", "2"); //2表示手机 values.put("data1", phoneNumber); mResolver.insert(uri, values); values.clear(); return true; } else { return false; } }
Example #10
Source File: ContactsHelper.java From NonViewUtils with Apache License 2.0 | 5 votes |
/** * 添加一个联系人数据 * * @return 返回true表示添加成功,false表示失败 */ public boolean insert(String name, String phoneNumber) { //根据号码找数据,如果存在则不添加 if (getNameByPhoneNumber(phoneNumber) == null) { //插入raw_contacts表,并获取_id属性 Uri uri = Uri.parse("content://com.android.contacts/raw_contacts"); ContentResolver resolver = mContext.getContentResolver(); ContentValues values = new ContentValues(); long contact_id = ContentUris.parseId(resolver.insert(uri, values)); //插入data表 uri = Uri.parse("content://com.android.contacts/data"); //添加姓名 values.put("raw_contact_id", contact_id); values.put(Data.MIMETYPE, "vnd.android.cursor.item/name"); values.put("data2", name); resolver.insert(uri, values); values.clear(); //添加手机号码 values.put("raw_contact_id", contact_id); values.put(Data.MIMETYPE, "vnd.android.cursor.item/phone_v2"); values.put("data2", "2"); //2表示手机 values.put("data1", phoneNumber); resolver.insert(uri, values); values.clear(); return true; } else { return false; } }