SoFunction
Updated on 2025-04-10

A brief analysis of Android mobile phone guard reading contact person

Recommended reading:

Brief analysis of Android mobile phone guard sim card binding

An in-depth analysis of the md5 encryption when the Android mobile phone guard saves password

Detailed explanation of Android Mobile Phone Guard Settings Wizard Page

Brief analysis Android phone guard turns off automatic update

A brief analysis of the properties of Android mobile phone guard custom control

Get the ContentResolver content parser object, and use the getContentResolver() method

Call the query() method of the ContentResolver object to get the data in the raw_contacts table, and get the Cursor object

Parameters: Uri object, field String array

Get the Uri object, through the ("content:///raw_contacts") method,

While looping the Cursor object, condition that the Cursor object moveToNext() method is true

Call the getString() method of the Cursor object, the parameter is the index

Determine that it is not null, query another table

Call the query() method of the ContentResolver object to get the data in the data table and get the Cursor object

Parameters: Uri object, field String[] array (data1, mimetype), condition String, condition value String[] array (contact_id)

The Uri object is ("content:///data")

The loop is the same as above

The corresponding type of name is /name

The corresponding type of phone is /phone_v2

Permission required, .READ_CONTACTS

Call the setAdapter() method of the ListView object to allocate data to the view, and the parameter is the Adapter object

Get Adapter object through new SimpleAdapter()

Parameters: context, data collection, layout resource, field String[] array, control int[] id array

package ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
/**
 * Read mobile phone contacts
 * @author taoshihan
 *
 */
public class PhoneContactsUtil {
public static List<Map<String,String>> getContacts(Context context){
ContentResolver resolver=();
Uri uri=("content:///raw_contacts");
Uri dataUri=("content:///data");
List<Map<String,String>> contacts=new ArrayList<Map<String,String>>();
//Cyclic contact tableCursor cursor=(uri, new String[]{"contact_id"}, null, null, null);
while(()){
String id=(("contact_id"));
if(id!=null){
Map<String,String> contact=new HashMap<String,String>();
//Looking for data tableCursor dataCursor=(dataUri, new String[]{"data1","mimetype"},"raw_contact_id=?", new String[]{id}, null);
while(()){
String data1=(("data1"));
String mimetype=(("mimetype")); 
("data1:"+data1+",mimetype:"+mimetype);
if(("/name")){
("name", data1);
}else if(("/phone_v2")){
("phone", data1);
}
}
(contact);
();
}
}
();
return contacts;
}
}

The above content is a related introduction to Android Mobile Guard reading contacts introduced by the editor. I hope it will be helpful to everyone!