In the Android operating system, programmers can make some modifications based on their own needs to easily complete various functions. This open-source system is undoubtedly a development opportunity for mobile phone manufacturers. Here we will introduce a method for Android to query contact information to help you solve some problems.
The following Android function is used to query the contact name, phone number, and email address,
- String columns [] = new String [] {People. _ ID, People. NAME,
People. NUMBER, People. PRIMARY_EMAIL_ID,
- People. PRIMARY_ORGANIZATION_ID, People.
PRIMARY_PHONE_ID, People. DISPLAY_NAME,
- People. IM_ACCOUNT, People. IM_HANDLE, People. PHONETIC_NAME, People. TYPE };
- Uri mContacts = People. CONTENT_URI;
- Cursor cur = managedQuery (mContacts, columns, // data field to be returned
- Null, // WHERE clause
- Null, // WHERE clause Parameters
- People. NAME // Order-by clause
- );
- If (cur. moveToFirst ()){
- Cursor newcur = null;
- Do {
- // Obtain the field value
- String name = cur. getString (cur. getColumnIndex (People. NAME ));
- String phoneNo = cur. getString (cur. getColumnIndex (People. NUMBER ));
- String peopleId = cur. getString (cur. getColumnIndex (People. _ ID ));
- String [] PROJECTION = new String [] {Contacts. ContactMethods. _ ID,
Contacts. ContactMethods. KIND, Contacts. ContactMethods. DATA };
- Newcur = managedQuery (Contacts. ContactMethods. CONTENT_URI,
PROJECTION, Contacts. ContactMethods. PERSON_ID + "= \'"
- + Cur. getLong (cur. getColumnIndex (People. _ ID) + "\ '", null, null );
- StartManagingCursor (newcur );
- String email = "";
- If (newcur. moveToFirst ()){
- Email = newcur. getString (newcur. getColumnIndex
(Contacts. ContactMethods. DATA ));
- }
- Log.info ("name =" + name +"
PhoneNo = "+ phoneNo +" email = "+ email );
- If (email! = Null &&! "". Equals (email )&&
Email. trim (). length ()! = 0 ){
- // You can obtain the contact email here.
- }
- } While (cur. moveToNext ());
- If (newcur! = Null ){
- Newcur. close (); // close once used up
- }
- }
- If (cur! = Null)
- Cur. close (); // close once used up
By querying the email address above, you can query the contact's address information, company information, and so on. The specific Android Method for querying contact information is described here.