//Get Contact person//"Display_name COLLATE Localized": Alphabetical order by namecursor cursor = getcontentresolver (). Query (ContactsContract.Contacts.CONTENT_URI,NULL,NULL,NULL, "Display_name COLLATE localized");//Traverse Contacts while(Cursor.movetonext ()) {String Phonesnumber="";//Phone number//Get Contact IDString contactId =cursor.getstring (Cursor.getcolumnindex (contactscontract.contacts._id));//get phone number according to current contact ID, number may have multipleCursor phones = Contentresolver.query (ContactsContract.CommonDataKinds.Phone.CONTENT_URI,NULL, contactscontract.commondatakinds.phone.contact_id+ "=" +contactid,NULL,NULL);//get name of contact personString DisplayName =cursor.getstring (Cursor.getcolumnindex (ContactsContract.Contacts.DISPLAY_NAME));//determine if the number is emptyif(Phones.movetofirst ()) {//Traverse number Do{Phonesnumber+ = Phones.getstring (Phones.getcolumnindex (ContactsContract.CommonDataKinds.Phone.NUMBER)) + "\t\t"; } while(Phones.movetonext ()); } String showcontract+ = displayname+ ":" +phonesnumber+ "\ n";}
Android get contacts and sort by pinyin