/*** Read Contacts *@paramContext *@return */ Public StaticList<map<string, string>>getlocalcontacts (Context context) {List<map<string, string>> datas =NewArraylist<map<string,string>>(); Contentresolver CR=Context.getcontentresolver (); Uri urirawcontacts= Uri.parse ("Content://com.android.contacts/raw_contacts"); Uri Uridata= Uri.parse ("Content://com.android.contacts/data"); Cursor Rawcontactscursor=cr.query (urirawcontacts,NewString[] {"contact_id"}, NULL, NULL, NULL); String data1=NULL; String mimetype=NULL; while(Rawcontactscursor.movetonext ()) {String contactId= Rawcontactscursor.getstring (Rawcontactscursor.getcolumnindex ("contact_id")); if(ContactId! =NULL) {Map<string, string> data =NewHashmap<string,string>(); Cursor Datacursor=cr.query (Uridata,Newstring[]{"Data1", "MimeType"}, "Contact_id=?", NewString[]{contactid},NULL); while(Datacursor.movetonext ()) {data1= Datacursor.getstring (Datacursor.getcolumnindex ("Data1")); MimeType= Datacursor.getstring (Datacursor.getcolumnindex ("MimeType")); if("Vnd.android.cursor.item/name". Equals (MimeType)) {Data.put ("Name", data1); //log.i (Staticdatas.contactshelperutil_log_tag, "name is" + data1);}Else if("Vnd.android.cursor.item/phone_v2". Equals (MimeType)) {Data.put ("Phone", data1); //log.i (Staticdatas.contactshelperutil_log_tag, "phone is" + data1);}} datas.add (data); Datacursor.close (); }} rawcontactscursor.close (); returndatas; }
Read all of your phone's local contacts