本章和大家分享的是手机通讯录方面的经验,需求背景:对手机通讯录进行增、删、改、查,或者有时候App需要与手机 contacts进行交互或共享contacts。
我们都知道android系统没有完全将contacts向developer开放,开发人员只能通过android提供的有限的Api对contacts进行操作,我们只能通过ContentProvider对contacts的数据进行增、删、改、查等操作,并不能改变到其表结构。
首先,我们来看下如何通过ContentProvider查找contacts,以下我以查找其姓、名、公司、家庭电话、工作电话、移动电话、传真、邮箱、城市、省份、国家、出生年月为例:
1 /**
2 * 取得family_name和given_name
3 */
4 Cursor nameCur=cr.query(ContactsContract.Data.CONTENT_URI,
5 new String[] {Data.CONTACT_ID, StructuredName.DISPLAY_NAME, StructuredName.FAMILY_NAME, StructuredName.GIVEN_NAME, StructuredName.MIDDLE_NAME},
6 ContactsContract.Data.CONTACT_ID + "=?" + " AND "
7 + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE + "'",
8 new String[]{android_id}, null);
9 if(nameCur.moveToFirst()){
10 firstName=nameCur.getString(nameCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME));
11 lastName=nameCur.getString(nameCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME));
12 }
13 nameCur.close();
14
15 Cursor companyCur=cr.query(ContactsContract.Data.CONTENT_URI,
16 new String[] {CommonDataKinds.Organization.COMPANY},
17 ContactsContract.Data.CONTACT_ID + "=?" + " AND "
18 + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE + "'",
19 new String[]{android_id}, null);
20
21 if(companyCur.moveToFirst()){
22 company=companyCur.getString(companyCur.getColumnIndex(CommonDataKinds.Organization.COMPANY));
23 }
24 companyCur.close();
25
26 // 根据contact_ID取得HomePhone号码
27 Cursor homePhoneCur = cr.query(ContactsContract.Data.CONTENT_URI,
28 new String[] {ContactsContract.CommonDataKinds.Phone.NUMBER},
29 ContactsContract.Data.CONTACT_ID + "=?" + " AND "
30 + ContactsContract.Data.MIMETYPE + "=? "+" AND "
31 +ContactsContract.CommonDataKinds.Phone.TYPE + "=?",
32 new String[]{android_id,ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE,String.valueOf(ContactsContract.CommonDataKinds.Phone.TYPE_HOME)}, null);
33 if(homePhoneCur.moveToFirst()){
34 homePhone=homePhoneCur.getString(homePhoneCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
35 }
36 homePhoneCur.close();
37
38 // 根据contact_ID取得WorkPhone号码
39 Cursor workPhoneCur = cr.query(ContactsContract.Data.CONTENT_URI,
40 new String[] {ContactsContract.CommonDataKinds.Phone.NUMBER},
41 ContactsContract.Data.CONTACT_ID + "=?" + " AND "
42 + ContactsContract.Data.MIMETYPE + "=? "+" AND "
43 +ContactsContract.CommonDataKinds.Phone.TYPE + "=?",
44 new String[]{android_id,ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE,String.valueOf(ContactsContract.CommonDataKinds.Phone.TYPE_WORK)}, null);
45 if(workPhoneCur.moveToFirst()){
46 workPhone=workPhoneCur.getString(workPhoneCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
47 }
48 workPhoneCur.close();
49
50 // 根据contact_ID取得MobilePhone号码
51 Cursor mobilePhoneCur = cr.query(ContactsContract.Data.CONTENT_URI,
52 new String[] {ContactsContract.CommonDataKinds.Phone.NUMBER},
53 ContactsContract.Data.CONTACT_ID + "=?" + " AND "
54 + ContactsContract.Data.MIMETYPE + "=? "+" AND "
55 +ContactsContract.CommonDataKinds.Phone.TYPE + "=?",
56 new String[]{android_id,ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE,String.valueOf(ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE)}, null);
57 if(mobilePhoneCur.moveToFirst()){
58 mobilePhone=mobilePhoneCur.getString(mobilePhoneCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
59 }
60 mobilePhoneCur.close();
61
62 // 根据contact_ID取得MobilePhone号码
63 Cursor faxPhoneCur = cr.query(ContactsContract.Data.CONTENT_URI,
64 new String[] {ContactsContract.CommonDataKinds.Phone.NUMBER},
65 ContactsContract.Data.CONTACT_ID + "=?" + " AND "
66 + ContactsContract.Data.MIMETYPE + "=? "+" AND "
67 +ContactsContract.CommonDataKinds.Phone.TYPE + "=?",
68 new String[]{android_id,ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE,String.valueOf(ContactsContract.CommonDataKinds.Phone.TYPE_FAX_HOME)}, null);
69 if(faxPhoneCur.moveToFirst()){
70 faxPhone=faxPhoneCur.getString(faxPhoneCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
71 }
72 faxPhoneCur.close();
73
74 // 根据contact_ID取得MobilePhone号码
75 Cursor emailCur = cr.query(ContactsContract.Data.CONTENT_URI,
76 new String[] {ContactsContract.CommonDataKinds.Email.DATA},
77 ContactsContract.Data.CONTACT_ID + "=?" + " AND "
78 + ContactsContract.Data.MIMETYPE + "=? "+" AND "
79 +ContactsContract.CommonDataKinds.Phone.TYPE + "=?",
80 new String[]{android_id,ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE,String.valueOf(ContactsContract.CommonDataKinds.Email.TYPE_WORK)}, null);
81 if(emailCur.moveToFirst()){
82 email=emailCur.getString(emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
83 }
84 emailCur.close();
85
86 // 根据contact_ID取得MobilePhone号码
87 Cursor addressCur = cr.query(ContactsContract.Data.CONTENT_URI,
88 new String[] {ContactsContract.CommonDataKinds.StructuredPostal.CITY,ContactsContract.CommonDataKinds.StructuredPostal.REGION,
89 ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY},
90 ContactsContract.Data.CONTACT_ID + "=?" + " AND "
91 + ContactsContract.Data.MIMETYPE + "=? ",
92 new String[]{android_id,ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE}, null);
93 if(addressCur.moveToFirst()){
94 city=addressCur.getString(addressCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.CITY));
95 state=addressCur.getString(addressCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.REGION));
96 country=addressCur.getString(addressCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY));
97 }
98 addressCur.close();
99
100 // 根据contact_ID取得MobilePhone号码
101 Cursor birthdayCur = cr.query(ContactsContract.Data.CONTENT_URI,
102 new String[] {ContactsContract.CommonDataKinds.Event.DATA},
103 ContactsContract.Data.CONTACT_ID + "=?" + " AND "
104 + ContactsContract.Data.MIMETYPE + "=? "+" AND "
105 + ContactsContract.CommonDataKinds.Event.TYPE + "=? ",
106 new String[]{android_id,ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE,String.valueOf(ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY)}, null);
107 if(birthdayCur.moveToFirst()){
108 birthday=birthdayCur.getString(birthdayCur.getColumnIndex(ContactsContract.CommonDataKinds.Event.DATA));
109 }
110 birthdayCur.close();
以上只是查找了contacts的部分字段,同鞋们可以自行拓展,比如说查找其IM,Organization,Nickname,WebSite等等.
得到contacts联系人之后,我们可以对其做相应的修改,修改完成后,我们要将数据更新到android contacts数据库中,以下就是更新的范例:
1 ArrayList ops =
2 new ArrayList();
3 // 更新family_name和given_name
4 ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
5 .withSelection(ContactsContract.Data.CONTACT_ID + "=?" + " AND "
6 + ContactsContract.Data.MIMETYPE + "=?",
7 new String[]{android_id,ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE})
8 .withValue(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, firstN)
9 .withValue(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, lastN)
10 .build());
11 // 更新comany
12 ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
13 .withSelection(ContactsContract.Data.CONTACT_ID + "=?" + " AND "
14 + ContactsContract.Data.MIMETYPE + "=?"+ " AND "
15 + ContactsContract.CommonDataKinds.Organization.TYPE + "=?",
16 new String[]{android_id,ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE,String.valueOf(ContactsContract.CommonDataKinds.Organization.TYPE_WORK)})
17 .withValue(ContactsContract.CommonDataKinds.Organization.COMPANY, com)
18 .build());
19 // 更新homePhone
20 ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
21 .withSelection(ContactsContract.Data.CONTACT_ID + "=?" + " AND "
22 + ContactsContract.Data.MIMETYPE + "=?"+ " AND "
23 + ContactsContract.CommonDataKinds.Organization.TYPE + "=?",
24 new String[]{android_id,ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE,String.valueOf(ContactsContract.CommonDataKinds.Phone.TYPE_HOME)})
25 .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, hp)
26 .build());
27 // 更新workPhone
28 ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
29 .withSelection(ContactsContract.Data.CONTACT_ID + "=?" + " AND "
30 + ContactsContract.Data.MIMETYPE + "=?"+ " AND "
31 + ContactsContract.CommonDataKinds.Organization.TYPE + "=?",
32 new String[]{android_id,ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE,String.valueOf(ContactsContract.CommonDataKinds.Phone.TYPE_WORK)})
33 .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER,wp)
34 .build());
35 // 更新mobilePhone
36 ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
37 .withSelection(ContactsContract.Data.CONTACT_ID + "=?" + " AND "
38 + ContactsContract.Data.MIMETYPE + "=?"+ " AND "
39 + ContactsContract.CommonDataKinds.Organization.TYPE + "=?",
40 new String[]{android_id,ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE,String.valueOf(ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE)})
41 .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER,mp)
42 .build());
43 // 更新faxPhone
44 ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
45 .withSelection(ContactsContract.Data.CONTACT_ID + "=?" + " AND "
46 + ContactsContract.Data.MIMETYPE + "=?"+ " AND "
47 + ContactsContract.CommonDataKinds.Organization.TYPE + "=?",
48 new String[]{android_id,ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE,String.valueOf(ContactsContract.CommonDataKinds.Phone.TYPE_FAX_HOME)})
49 .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER,fp)
50 .build());
51 // 更新email
52 ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
53 .withSelection(ContactsContract.Data.CONTACT_ID + "=?" + " AND "
54 + ContactsContract.Data.MIMETYPE + "=?"+ " AND "
55 + ContactsContract.CommonDataKinds.Email.TYPE + "=?",
56 new String[]{android_id,ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE,String.valueOf(ContactsContract.CommonDataKinds.Email.TYPE_WORK)})
57 .withValue(ContactsContract.CommonDataKinds.Email.DATA,em)
58 .build());
59 // 更新city,state,country
60 ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
61 .withSelection(ContactsContract.Data.CONTACT_ID + "=?" + " AND "
62 + ContactsContract.Data.MIMETYPE + "=?"+ " AND "
63 + ContactsContract.CommonDataKinds.StructuredPostal.TYPE + "=?",
64 new String[]{android_id,ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE,String.valueOf(ContactsContract.CommonDataKinds.StructuredPostal.TYPE_HOME)})
65 .withValue(ContactsContract.CommonDataKinds.StructuredPostal.CITY, city)
66 .withValue(ContactsContract.CommonDataKinds.StructuredPostal.REGION, state)
67 .withValue(ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY,cou)
68 .build());
69 // 更新birthday
70 ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
71 .withSelection(ContactsContract.Data.CONTACT_ID + "=?" + " AND "
72 + ContactsContract.Data.MIMETYPE + "=?"+ " AND "
73 + ContactsContract.CommonDataKinds.Event.TYPE + "=?",
74 new String[]{android_id,ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE,String.valueOf(ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY)})
75 .withValue(ContactsContract.CommonDataKinds.Event.DATA, bir)
76 .build());
77 try
78 {
79 ContentProviderResult[] res = context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
80 // Log.i("contact", "android_id="+android_id+",firstName="+firstName+",lastName="+lastName);
81 // appState.db.insertContactToTag(tagId,String.valueOf(contactId));
82 }
83 catch (RemoteException e)
84 {
85 // error
86 }catch (OperationApplicationException e)
87 {
88 // error
89 }
同样以上更新也仅是对contact的部分字段进行了更新,我相信聪明的你,仔细阅读,细细推敲一番,定能找到其中的规律,从而对犹如IM,Nickname,Event,Organization等字段进行更新。
以上只是对已经存在的contacts进行操作,那么我们一开始该如何向里面插入一条数据呢,以下代码是实现向数据库中插入一条数据的操作。
1 ArrayList ops = new ArrayList();
2 int rawContactInsertIndex = ops.size();
3
4 ops.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
5 .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null)
6 .withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null)
7 .build());
8
9 //------------------------------------------------------ Names
10 if(firstN != null && lastN!=null )
11 {
12 ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
13 .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, rawContactInsertIndex)
14 .withValue(ContactsContract.Data.MIMETYPE,
15 ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
16 .withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, firstN+lastN)
17 .withValue(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, firstN)
18 .withValue(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, lastN)
19 .build());
20 }
21
22 //------------------------------------------------------ Organization
23 if(com!=null)
24 {
25 ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
26 .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, rawContactInsertIndex)
27 .withValue(ContactsContract.Data.MIMETYPE,
28 ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
29 .withValue(ContactsContract.CommonDataKinds.Organization.COMPANY, com)
30 .withValue(ContactsContract.CommonDataKinds.Organization.TYPE, ContactsContract.CommonDataKinds.Organization.TYPE_WORK)
31 .build());
32 }
33
34 //------------------------------------------------------ Home Numbers
35 if(hp!= null)
36 {
37 ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
38 .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, rawContactInsertIndex)
39 .withValue(ContactsContract.Data.MIMETYPE,
40 ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
41 .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, hp)
42 .withValue(ContactsContract.CommonDataKinds.Phone.TYPE,
43 ContactsContract.CommonDataKinds.Phone.TYPE_HOME)
44 .build());
45 }
46 //------------------------------------------------------ Work Numbers
47 if(wp != null)
48 {
49 ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
50 .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, rawContactInsertIndex)
51 .withValue(ContactsContract.Data.MIMETYPE,
52 ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
53 .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, wp)
54 .withValue(ContactsContract.CommonDataKinds.Phone.TYPE,
55 ContactsContract.CommonDataKinds.Phone.TYPE_WORK)
56 .build());
57 }
58 //------------------------------------------------------ Mobile Number
59 if(mp != null)
60 {
61 ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
62 .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, rawContactInsertIndex)
63 .withValue(ContactsContract.Data.MIMETYPE,
64 ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
65 .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, mp)
66 .withValue(ContactsContract.CommonDataKinds.Phone.TYPE,
67 ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE)
68 .build());
69 }
70 //------------------------------------------------------ Fax Number
71 if(fp != null)
72 {
73 ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
74 .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, rawContactInsertIndex)
75 .withValue(ContactsContract.Data.MIMETYPE,
76 ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
77 .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, fp)
78 .withValue(ContactsContract.CommonDataKinds.Phone.TYPE,
79 ContactsContract.CommonDataKinds.Phone.TYPE_FAX_HOME)
80 .build());
81 }
82
83 //------------------------------------------------------ Email
84 if(em != null)
85 {
86 ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
87 .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, rawContactInsertIndex)
88 .withValue(ContactsContract.Data.MIMETYPE,
89 ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
90 .withValue(ContactsContract.CommonDataKinds.Email.DATA, em)
91 .withValue(ContactsContract.CommonDataKinds.Email.TYPE, ContactsContract.CommonDataKinds.Email.TYPE_WORK)
92 .build());
93 }
94 //------------------------------------------------------ City,state,country
95 if(city != null)
96 {
97 ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
98 .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, rawContactInsertIndex)
99 .withValue(ContactsContract.Data.MIMETYPE,
100 ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE)
101 .withValue(ContactsContract.CommonDataKinds.StructuredPostal.CITY, city)
102 .withValue(ContactsContract.CommonDataKinds.StructuredPostal.REGION, state)
103 .withValue(ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY,cou)
104 .withValue(ContactsContract.CommonDataKinds.StructuredPostal.TYPE,
105 ContactsContract.CommonDataKinds.StructuredPostal.TYPE_HOME)
106 .build());
107 }
108
109 //------------------------------------------------------ Birthday
110 if(bir != null)
111 {
112 ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
113 .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, rawContactInsertIndex)
114 .withValue(ContactsContract.Data.MIMETYPE,
115 ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE)
116 .withValue(ContactsContract.CommonDataKinds.Event.DATA, bir)
117 .withValue(ContactsContract.CommonDataKinds.Event.TYPE,
118 ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY)
119 .build());
120 }
121 try
122 {
123 ContentProviderResult[] res = context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
124
125 return res;
126 }
127 catch (RemoteException e)
128 {
129 // error
130 }catch (OperationApplicationException e)
131 {
132 // error
133 }
实现以上代码便可将一条数据插入到contacts数据库中,同样,你也可以插入其他的字段,而且你也可以细细研究下ContentProviderResult[],看看进行这些操作后,其返回的结果都是什么。
以上实现了对android contacts 增、删、改、查中的三种,下面的代码就是实现删的,删除一个contacts相对来说比较简单些。
1 String where = ContactsContract.Data._ID + " = ? ";
2 String[] params = new String[] {android_id};
3
4 ArrayList ops = new ArrayList();
5 ops.add(ContentProviderOperation.newDelete(ContactsContract.RawContacts.CONTENT_URI)
6 .withSelection(where, params)
7 .build());
8 try {
9 cr.applyBatch(ContactsContract.AUTHORITY, ops);
10 } catch (RemoteException e) {
11 // TODO Auto-generated catch block
12 e.printStackTrace();
13 } catch (OperationApplicationException e) {
14 // TODO Auto-generated catch block
15 e.printStackTrace();
16 }
删除一个contacts有很多的选择,你可以只删除电话这一块,也可以删除联系人信息这一块,而且你不仅可以将id做作为条件进行删除,你也可以将联系电话做为条件进行删除,你也还可以以用户名做为条件进行删除。
以上代码便可以实现对android contacts的增、删、改、查等操作。最后不要忘了赋予APP 对contacts读写的权限: