A brief analysis of Android phone defender read Contact person _android

Source: Internet
Author: User
Tags md5 encryption

Recommended reading:

An analysis of Android phone defender SIM card binding

An in-depth analysis of the Android phone defender MD5 encryption when saving passwords

Detailed Android Phone Guardian Settings Wizard page

An analysis of Android phone defender turn off automatic Updates

A brief analysis of Android phone defender custom control properties

Gets the Contentresolver content parser object, passing the Getcontentresolver () method

Call the Contentresolver object's query () method, get the data in the Raw_contacts table, get the cursor object

Parameters: Uri object, field string array

Gets the URI object, through the Uri.parse ("Content://com.android.contacts/raw_contacts") method,

The while loop cursor the object, provided that the cursor object MoveToNext () method is True

Invokes the GetString () method of the cursor object, which is an index

Judge is not NULL, query another table

Call the Contentresolver object's query () method, get the data in the table, get the cursor object

Parameters: Uri object, field string[] Array (data1,mimetype), condition string, conditional value string[] Array (contact_id)

Uri object is Uri.parse ("Content://com.android.contacts/data")

Loops are the same as above

The name corresponds to the type is Vnd.android.cursor.item/name

The corresponding type of telephone is VND.ANDROID.CURSOR.ITEM/PHONE_V2

Need permission, Android.permisssion.READ_CONTACTS

Invokes the Setadapter () method of the ListView object, assigning data to the view, and the parameter is a adapter object

Get adapter object with new Simpleadapter ()

Parameters: Context, data collection, layout resource, field string[] array, control int[] ID array

Package com.qingguow.mobilesafe.utils;
Import java.util.ArrayList;
Import Java.util.HashMap;
Import java.util.List;
Import Java.util.Map;
Import Android.content.ContentResolver;
Import Android.content.Context;
Import Android.database.Cursor;
Import Android.net.Uri;  /** * Read Mobile contact * @author Taoshihan * */public class Phonecontactsutil {public static list<map<string,string>>
Getcontacts (Context context) {Contentresolver resolver=context.getcontentresolver ();
Uri uri=uri.parse ("content://com.android.contacts/raw_contacts");
Uri datauri=uri.parse ("Content://com.android.contacts/data");
List<map<string,string>> contacts=new arraylist<map<string,string>> ();
Loop Contact table Cursor Cursor=resolver.query (URI, new string[]{"contact_id"}, NULL, NULL, NULL); while (Cursor.movetonext ()) {String id=cursor.getstring (Cursor.getcolumnindex ("contact_id")); if (id!=null) {Map<
String,string> contact=new hashmap<string,string> (); Find data Table Cursor DATACURSOR=RESOLVER.QUery (Datauri, New string[]{"Data1", "MimeType"}, "Raw_contact_id=?", New String[]{id}, NULL);
while (Datacursor.movetonext ()) {String data1=datacursor.getstring (Datacursor.getcolumnindex ("data1")); 
String mimetype=datacursor.getstring (Datacursor.getcolumnindex ("mimetype"));
System.out.println ("Data1:" +data1+ ", MimeType:" +mimetype); if (Mimetype.equals ("Vnd.android.cursor.item/name")) {contact.put ("name", data1);}
else if (mimetype.equals ("Vnd.android.cursor.item/phone_v2")) {contact.put ("phone", data1);}
Contacts.add (contact);
Datacursor.close ();
} cursor.close ();
return contacts; }
}

The above content is small series to introduce the Android phone Guardian to read the relevant introduction of contact people, I hope to help you!

Related Article

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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.