life02

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  197 随笔 :: 3 文章 :: 37 评论 :: 0 Trackbacks
http://blog.csdn.net/qiaoning13256/article/details/6889315

 1 
 2 /**
 3 * 获得收藏夹的联系人
 4 */
 5 private void getKeepedContacts(){
 6 Cursor cur = getContentResolver().query(  
 7                 ContactsContract.Contacts.CONTENT_URI, null, ContactsContract.Contacts.STARRED + " =  1 " , nullnull);  
 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             Cursor pcur = getContentResolver().query(  
17                     ContactsContract.CommonDataKinds.Phone.CONTENT_URI,  
18                     null,  
19                     ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "="  
20                             + Long.toString(id), nullnull);  
21    
22             // 处理多个号码的情况  
23             String phoneNumbers = "";  
24             while (pcur.moveToNext()) {  
25                 String strPhoneNumber = pcur  
26                         .getString(pcur  
27                                 .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));  
28                 phoneNumbers += strPhoneNumber + ":";  
29             }  
30             phoneNumbers += "\n";  
31             pcur.close();
32             String name = cur.getString(cur.getColumnIndex("display_name"));
33             contactNameList.add(name);
34             contactNumList.add(phoneNumbers);
35         }  
36         cur.close();
37 }
posted on 2012-03-19 16:31 life02 阅读(412) 评论(0)  编辑 收藏 引用 所属分类: Android开发

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理