android之获取联系人并按拼音排序
//获取联系人 //“display_name COLLATE LOCALIZED”:按姓名的拼音排序 Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, "display_name COLLATE LOCALIZED"); //遍历联系人 while(cursor.moveToNext()){ String phonesNumber=""; //电话号码 //获取联系人ID String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)); //按照当前联系人ID获取电话号码,号码可能有多个 Cursor phones = contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID+"="+contactId, null, null); //获取联系人姓名 String displayName = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); //判断号码是否为空 if (phones.moveToFirst()) { //遍历号码 do{ phonesNumber += phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER))+"\t\t"; }while(phones.moveToNext()); } String showContract+= displayName+":"+phonesNumber+"\n"; }