android中如何取得用户手机的常用联系人(即收藏夹的联系人)
16lz
2021-01-26
android中如何取得用户手机的常用联系人(即收藏夹的联系人) (转载) http://blog.csdn.net/qiaoning13256/article/details/6889315
1
2 /**
3 *获得收藏夹的联系人
4 */
5 private void getKeepedContacts(){
6 Cursorcur = getContentResolver().query(
7 ContactsContract.Contacts.CONTENT_URI, null ,ContactsContract.Contacts.STARRED + " =1 " , null , null );
8 startManagingCursor(cur);
9 int num = cur.getCount();
10 System.out.println(num + "" );
11 int count = 0 ;
12 while (cur.moveToNext()){
13 count ++ ;
14
15 long id = cur.getLong(cur.getColumnIndex( " _id " ));
16 Cursorpcur = getContentResolver().query(
17 ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
18 null ,
19 ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = "
20 + Long.toString(id), null , null );
21
22 // 处理多个号码的情况
23 StringphoneNumbers = "" ;
24 while (pcur.moveToNext()){
25 StringstrPhoneNumber = pcur
26 .getString(pcur
27 .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
28 phoneNumbers += strPhoneNumber + " : " ;
29 }
30 phoneNumbers += " \n " ;
31 pcur.close();
32 Stringname = cur.getString(cur.getColumnIndex( " display_name " ));
33 contactNameList.add(name);
34 contactNumList.add(phoneNumbers);
35 }
36 cur.close();
37 }
1
2 /**
3 *获得收藏夹的联系人
4 */
5 private void getKeepedContacts(){
6 Cursorcur = getContentResolver().query(
7 ContactsContract.Contacts.CONTENT_URI, null ,ContactsContract.Contacts.STARRED + " =1 " , null , null );
8 startManagingCursor(cur);
9 int num = cur.getCount();
10 System.out.println(num + "" );
11 int count = 0 ;
12 while (cur.moveToNext()){
13 count ++ ;
14
15 long id = cur.getLong(cur.getColumnIndex( " _id " ));
16 Cursorpcur = getContentResolver().query(
17 ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
18 null ,
19 ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = "
20 + Long.toString(id), null , null );
21
22 // 处理多个号码的情况
23 StringphoneNumbers = "" ;
24 while (pcur.moveToNext()){
25 StringstrPhoneNumber = pcur
26 .getString(pcur
27 .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
28 phoneNumbers += strPhoneNumber + " : " ;
29 }
30 phoneNumbers += " \n " ;
31 pcur.close();
32 Stringname = cur.getString(cur.getColumnIndex( " display_name " ));
33 contactNameList.add(name);
34 contactNumList.add(phoneNumbers);
35 }
36 cur.close();
37 }
更多相关文章
- Android(安卓)---模拟手机发送短信
- android调用系统发短信传递电话号码和短信内容
- Android(安卓)MMS/SMS(二)
- ContactsContract获取联系人信息
- ContactsProvider2
- 11 Weeks of Android: 联系人与身份
- Android实现短信自动回复,挂电话
- EditTextView 带空格分隔的输入(电话号码,银行卡)
- Android内容提供者之读取联系人信息