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.
Body
1. General Usage of phonelookup. content_filter_uri
Uri URI
= URI. withappendedpath (phonelookup. content_filter_uri, Uri. encode (phonenumber ));
Resolver. Query (Uri, newstring [] {phonelookup. display_name,... copy the code
For the API, see here. If you use phonelookup. content_filter_uri as follows, the illegalargumentexception error is reported.
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); copy the code
This "*" means that 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.
Reprinted from:
Blog: http://www.cnblogs.com
Farmer's uncle: http://over140.cnblogs.com
Note:
I. Database cursor
For the returned object cursor, which is encapsulated by the androidsqlite database, it is prone to errors.
1. cursor may return null
If the cursor object returned by the query is null, any method to execute the cursor must have a null pointer. This android code 40% has not noticed.
2. cursor returns 0
We can only judge whether it is null or not. If the cursor object is 0, we will execute movetofirst (). This method will be embarrassing. This is a prompt for attention outside the android development grid.
3. When traversing cursor, no movetofirst () is executed, so that the cursor position is uncertain.
4. manually close cursor after use. Do not forget the cursor. Close () method.
5. Obtain the cursor type, such as getint and getlong. Since the Boolean and long types in SQLite are all SQLite integers, remember to convert them during reading.