Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to query contact information in Android

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report