[Android] Using PhoneLookup to read all phone numbers

Source: Internet
Author: User

Preface

When reading the address book of the Android system, the contacts are generally read first and then their numbers are read in a nested loop. If the number of contacts in the address book is small, the speed is acceptable, but the number of people in the address book is 1 to 2, I am afraid it will be slow. If the hardware is almost worse, the experience will be worse. Available

ContactsContract. CommonDataKinds. Phone. CONTENT_URI (corresponding to the contacts2.db data view metadata) view to avoid nested reading, but PhoneLookup. CONTENT_FILTER_URI cannot be used directly. Here are some tips.

 

Statement

You are welcome to repost, but please keep the original source of the article :)

Blog: http://www.cnblogs.com

Farmer's uncle: http://over140.cnblogs.com

 

Body

1. General Usage of PhoneLookup. CONTENT_FILTER_URI

Uri uri = Uri. withAppendedPath (PhoneLookup. CONTENT_FILTER_URI, Uri. encode (phoneNumber ));
Resolver. query (uri, new String [] {PhoneLookup. DISPLAY_NAME ,...

For the API, see here. If you use PhoneLookup. CONTENT_FILTER_URI as follows, the IllegalArgument Exception error is returned.

GetContentResolver (). query (PhoneLookup. CONTENT_FILTER_URI ,...

 

Ii. Tips and usage

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 );

The key is this "*". In this way, you can obtain the names of all numbers, related contacts, and other related fields, which is much easier than searching for their numbers through contacts.

 

Iii. Maintenance

2011-10-28 this test program passed the G7 test. The Android version is 2.2. Please also test it in this version or later. Please understand that the test conditions have not been specified before :)

 

End

The company's project is about to be tested and we look forward to seeing you early.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.