Android Get phone Address book contact information
Copy Code code as follows:
private void Getphonecontacts () {
Contentresolver resolver = This.getcontentresolver ();
Get Mobile Contact
Cursor phonecursor = Resolver.query (Phone.content_uri,
New string[] {phone.contact_id, phone.display_name,
Phone.number},
Phone.display_name + "=?" + "and" + phone.type + "= '"
+ Phone.type_mobile + "'", new string[] {name}, NULL);
if (phonecursor!= null) {
while (Phonecursor.movetonext ()) {
String number = phonecursor.getstring (2);
When the cell phone number is empty or skips the current loop for an empty field
if (Textutils.isempty (PhoneNumber))
Continue
Get Contact Name
String username = phonecursor.getstring (1);
Mcontactsname.add (ContactName);
Mcontactsnumber.add (PhoneNumber);
}
Phonecursor.close ();
}
}
Get phone SIM card contact information
SIM card and mobile phone I get similar way just URL a bit different, need to note that the SIM card is not contact person avatar.
Copy Code code as follows:
private void Getsimcontacts () {
Contentresolver resolver = Mcontext.getcontentresolver ();
Get Sims Card Contacts
Uri uri = uri.parse ("Content://icc/adn");
Cursor phonecursor = Resolver.query (URI,
New string[] {phone.contact_id, phone.display_name,
Phone.number},
Phone.display_name + "=?" + "and" + phone.type + "= '"
+ Phone.type_mobile + "'", new string[] {name}, NULL);
if (phonecursor!= null) {
while (Phonecursor.movetonext ()) {
String number = phonecursor.getstring (2);
When the cell phone number is empty or skips the current loop for an empty field
if (Textutils.isempty (PhoneNumber))
Continue
Get Contact Name
String username = phonecursor.getstring (1);
Mcontactsname.add (ContactName);
Mcontactsnumber.add (PhoneNumber);
}
Phonecursor.close ();
}
}
call the system to call the interface, the code is as follows.
Tel: Telephone number
Copy Code code as follows:
Call system method to call
Intent dialintent = new Intent (Intent.action_call, Uri.parse ("Tel:" + mcontactsnumber.get (position)));
StartActivity (dialintent);
Finally, do not forget to add permissions in the Androidmanifest.xml file, otherwise run the program is an error!
Copy Code code as follows:
<!--read Contact permissions-->
<uses-permission android:name= "Android.permission.READ_CONTACTS"/>
<!--call permission-->
<uses-permission android:name= "Android.permission.CALL_PHONE"/>