Android获取Contact Number的例子(2.0系统以前的获取方式)

  1. http://www.blogjava.net/caizh2009/archive/2010/12/17/341010.html
  2. String[] projection = new String[] {  
  3. People._ID,  
  4. People.NAME,  
  5. People.NUMBER,  
  6. };  
  7.   
  8. // Get the base URI for People table in Contacts content provider.  
  9. // which is: content://contacts/people/  
  10. Uri contactUri = People.CONTENT_URI;  
  11.   
  12. // Best way to retrieve a query; returns a managed query.  
  13. Cursor peopleCursor = managedQuery (contactUri,  
  14. projection, //Which columns to return.  
  15. null, // WHERE clause--we won't specify.  
  16. null, // Selection Args??  
  17. People.DEFAULT_SORT_ORDER); // Order-by name  
  18.   
  19. // go to the beginning of the list  
  20. peopleCursor.moveToFirst();  
  21.   
  22.   
  23. // So, here we have a contact. We need to get the contact ID (_id) then  
  24. // build the Uri to get the phones section of that user's record  
  25. // which is a subdirectory of a contact record  
  26.   
  27. long personId = peopleCursor.getLong(peopleCursor.getColumnIndex("_id"));  
  28.   
  29. Uri personUri = ContentUris.withAppendedId(contactUri, personId );  
  30.   
  31. // So now the URL looks like: content://contacts/people/_id(where the actual id of the record is here)  
  32. Uri phoneUri=  
  33. Uri.withAppendedPath(personUri, Contacts.People.Phones.CONTENT_DIRECTORY);  
  34.   
  35. // Now the URL looks like: content://contacts/people/_id/phones (where phones is literally "phones")  
  36.   
  37. // Now get all the phone numbers for this contact  
  38. Cursor phonesCursor = managedQuery(phoneUri,  
  39. null,  
  40. null,  
  41. null,  
  42. Phones.DEFAULT_SORT_ORDER);  
  43.   
  44. // We now have a cursor for all the phone numbers for that User ID  
  45. // go to the beginning of the phone list.  
  46. phonesCursor.moveToFirst();   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值