Get the App
SLTechnology News&Howtos  ›  Development  › 

How to query contact information in Android

Shulou Source: shulou.com Published: 2022-05-31 21:46:28 09月17日 Update

In this article, the editor introduces in detail "how to query contact information in Android". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to query contact information in Android" can help you solve your doubts.

The main function of Android to query contact information is to query the name, telephone number and e-mail address of the contact.

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

Parameters of the null, / / WHERE clause

People.NAME / / Order-by clause

);

If (cur.moveToFirst ()) {

Cursor newcur = null

Do {

/ / get the value of the field

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

/ / contact mail can be obtained here

}

} while (cur.moveToNext ())

If (newcur! = null) {

Newcur.close (); / / close it when you run out of it.

}

}

If (cur! = null)

Cur.close (); / / close it when you run out of it.

After reading this, the article "how to query contact information in Android" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.

Tags: Contact contact query information clause article content field mail proper function parameter address name idea data new knowledge more steps telephone Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MariaDB Microsoft Shulou Information Shulou Tech Info