Android get phone contact information
This article will reveal how Android can obtain mobile phone contact information.
Steps to obtain mobile phone contact information:
1. Get contentresolver
ContentResolver resolver = getContentResolver();
2、resolver. Query (*) query information
Query the URI of mobile phone contact: contactscontract RawContacts. CONTENT_ Uri to query the URI of the mobile phone number of the mobile phone contact: contactscontract CommonDataKinds. Phone. CONTENT_ Uri query URI of contact mailbox: contactscontract CommonDataKinds. Email. CONTENT_ URI
3. Based on contact name_ ID query the corresponding mobile phone number and email address
Find raw in mobile phone number and email query_ contact_ ID and contact_ Entries with equal IDS
The main codes are as follows:
MainActivity. java
Main layout activity_ main. xml
simple_ contacts_ item. xml
Read contact permissions:
<uses-permission android:name="android.permission.READ_CONTACTS"/>
Final rendering:
be careful:
Check whether the application is given the permission to read contacts; This example reads the contact information in the main thread, which is inefficient. If there are efficiency requirements, please find other methods by yourself.
Source code download address: http://xiazai.jb51.net/201610/yuanma/AndroidContactsDemo (jb51.net). rar
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.