String tmp = txtPhoneName.getText().toString();
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, "DISPLAY_NAME = '" + tmp + "'", null, null);
if (cursor.moveToFirst()) {
String contactId = Cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
Cursor phones = cr.query(Phone.CONTENT_URI, null, Phone.CONTACT_ID + " = " + contactId, null, null);
while (phones.moveToNext()) {
String number = phones.getString(phones.getColumnIndex(Phone.NUMBER));
number1 = number;
int type = phones.getInt(phones.getColumnIndex(Phone.TYPE));
switch (type) {
case Phone.TYPE_HOME:
// do something with the Home number here...
break;
case Phone.TYPE_MOBILE:
// do something with the Mobile number here...
break;
case Phone.TYPE_WORK:
// do something with the Work number here...
break;
}
}
phones.close();
}
My issue is that when it is at the switch statment it doesn’t check anything. It goes to the while(phones.moveToNext()) where is my error does Phone.TYPE_HOME is not int and my type can’t compare to it… And one last question, why for some contacts it gets the mobile number and for others the home (and in both cases the contacts have a home and a mobile number)? I want to get a number that starts with 07 and if there is no that kind of number to get whatever number there is for the contact, and then how to call that number… THX
It is probably because u haven put anything yet in the cases, try with int i=0; and see in the debugger