天天看點

[Android]通過PhoneLookup讀取所有電話号碼

前言

  讀取android系統的通訊錄時一般會先讀取聯系人然後再讀取其号碼,嵌套循環讀取。如果通訊錄人數不多速度尚可,但是通訊錄裡有1-2百人恐怕就比較慢了,如果硬體再差點體驗就更差了。可以使用

contactscontract.commondatakinds.phone.content_uri(對應contacts2.db的資料視圖view_data_restricted)視圖來讀取避免嵌套讀取,而對于phonelookup.content_filter_uri确不能直接使用,這裡分享一下小技巧。

聲明

  歡迎轉載,但請保留文章原始出處:) 

    部落格園:http://www.cnblogs.com

    農民伯伯: http://over140.cnblogs.com 

正文

  一、phonelookup.content_filter_uri的一般用法

 uri uri = uri.withappendedpath(phonelookup.content_filter_uri, uri.encode(phonenumber));

 resolver.query(uri, new string[]{phonelookup.display_name,...

getcontentresolver().query(phonelookup.content_filter_uri,...

  二、 技巧用法

        cursor c = getcontentresolver().query(uri.withappendedpath(

                phonelookup.content_filter_uri, "*"), new string[] {

                phonelookup._id,

                phonelookup.number,

                phonelookup.display_name,

                phonelookup.type, phonelookup.label }, null, null, sortorder);

    關鍵是這個"*",這樣就能取到所有的号碼以及相關的聯系人的姓名以及其他相關字段,比通過聯系人再查找其号碼要友善很多。

  三、 維護

     2011-10-28  本測試程式在g7上測試通過,android版本為2.2,還請大家在這版本以上測試,之前沒有寫明測試條件還請諒解:)

結束 

  公司的項目馬上要内測了,期待早一些與大家見面。 

轉載:http://www.cnblogs.com/over140/archive/2011/06/29/2091541.html

繼續閱讀