我想获取本地联系人的所有详细信息,并且我能够获取名字、姓氏、手机号码、家庭号码、工作号码。但是对于多个其他号码,我只得到一个其他号码。如何获取所有输入的其他数字?
Uri contactsUri = ContactsContract.Contacts.CONTENT_URI;
ContentResolver cr = getContentResolver();
// Querying the table ContactsContract.Contacts to retrieve all the contacts
Cursor contactsCursor = getContentResolver().query(contactsUri, null, null, null, ContactsContract.Contacts.DISPLAY_NAME + " ASC ");
if(contactsCursor != null && contactsCursor.getCount() > 0){
contactsCursor.moveToFirst();
do {
long contactId = contactsCursor.getLong(contactsCursor.getColumnIndex("_ID"));
Uri dataUri = ContactsContract.Data.CONTENT_URI;
// Querying the table ContactsContract.Data to retrieve individual items like
// home phone, mobile phone, work email etc corresponding to each contact
Cursor dataCursor = getContentResolver().query(dataUri, null, ContactsContract.Data.CONTACT_ID + "=" + contactId +" AND "+ContactsContract.CommonDataKinds.Phone.TYPE_OTHER +"=7", null, null);
if(dataCursor != null && dataCursor.getCount() > 0){
dataCursor.moveToFirst();
// Getting Display Name
displayName = dataCursor.getString(dataCursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME ));
do{
// Getting NickName
if(dataCursor.getString(dataCursor.getColumnIndex("mimetype")).equals(ContactsContract.CommonDataKinds.Nickname.CONTENT_ITEM_TYPE))
nickName = dataCursor.getString(dataCursor.getColumnIndex("data1"));
// Getting Phone numbers
if(dataCursor.getString(dataCursor.getColumnIndex("mimetype")).equals(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)){
switch(dataCursor.getInt(dataCursor.getColumnIndex("data2"))){
case ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE :
mobilePhone = dataCursor.getString(dataCursor.getColumnIndex("data1"));
break;
case ContactsContract.CommonDataKinds.Phone.TYPE_HOME :
homePhone = dataCursor.getString(dataCursor.getColumnIndex("data1"));
break;
case ContactsContract.CommonDataKinds.Phone.TYPE_WORK :
workPhone = dataCursor.getString(dataCursor.getColumnIndex("data1"));
break;
case ContactsContract.CommonDataKinds.Phone.TYPE_OTHER :
otherPhone1 = dataCursor.getString(dataCursor.getColumnIndex("data1"));
otherPhone2 = dataCursor.getString(dataCursor.getColumnIndex("data2"));
otherPhone3 = dataCursor.getString(dataCursor.getColumnIndex("data3"));
otherPhone4= dataCursor.getString(dataCursor.getColumnIndex("data4"));
otherPhone5 = dataCursor.getString(dataCursor.getColumnIndex("data5"));
Log.d("othertypes of numbersssssssss ", "other types of numbersssss "+otherPhone1+" "+otherPhone2+" "+otherPhone3);
break;
}
}