Android learning to get basic mobile phone contact information

Source: Internet
Author: User
Tags sqlite manager

Go directlyCode...

View code

 1 Cursor ccursor = getcontentresolver (). Query (contacts. content_uri, Null , Null , Null , Null );
2 Cursor dcursor;
3 Startmanagingcursor (ccursor );
4 While (Ccursor. movetonext ()){
5 // Get the name directly
6 System. Out. println ("name:" + ccursor. getstring (ccursor. getcolumnindex (contacts. display_name )));
7 // Query the data table based on the ID of the contacts table
8 Dcursor = getcontentresolver (). Query (data. content_uri, Null , Data. raw_contact_id + "=? ", New String [] {ccursor. getstring (ccursor. getcolumnindex (contacts. _ id ))}, Null );
9 Startmanagingcursor (dcursor );
10 While (Dcursor. movetonext ()){
11 // Determine whether the mimetype of this row in the data table is phone
12 If (Dcursor. getstring (dcursor. getcolumnindex (data. mimetype). Equals (phone. content_item_type )){ // Yes
13 // Value of the data2 field in the switchdata table
14 Switch (Dcursor. getint (dcursor. getcolumnindex (data. data2 ))){
15 // Phone. type_mobile indicates the mobile phone number.
16 Case Phone. type_mobile:
17 System. Out. println ("mobile phone number:" + dcursor. getstring (dcursor. getcolumnindex (data. data1 )));
18 Break ;
19 // Phone. type_home is a landline phone.
20 Case Phone. type_home:
21 System. Out. println ("landline:" + dcursor. getstring (dcursor. getcolumnindex (data. data1 )));
22 Break ;
23 }
24 }
25 }
26 }


The tables used in the contacts database

This table stores some contact IDs or something.

This table stores information about the corresponding IDs in the corresponding contacts table. the data category corresponds to mimetype_id. data1, data2, and so on. Different mimetype have different functions. For example, if mimetype is phone, data1 stores the phone number and data2 stores the category, for example, the mobile phone number, fixed phone number, company number, and so on. You will know what else you need.


We can use mimetype to determine what data is stored.


I use Firefox's SQLite manager to browse databases. I just need to export the corresponding database and use SQLite manager to open it. There are a lot of databases under data/data. You can find what you want.


Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.