I wnat to fetch out all contacts numbers + alternative numbers.
in first used this code:
Cursor phones = _context.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);
while (phones.moveToNext())
{
Log.d("states","name: "+ phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)) +" - number: "+ phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
}
phones.close();
but in this code if a name have 3 numbers only show me third number.
then used this code:
Cursor phones = _context.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);
while (phones.moveToNext())
{
String id = phones.getString(phones.getColumnIndex(ContactsContract.Contacts._ID));
String name = phones.getString(phones.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
if (Integer.parseInt(phones.getString(phones.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0)
{
Log.d("states","name : " + name + ", ID : " + id);
Cursor pCur = _context.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { id }, null);
Log.d("states",pCur.getCount()+""); \\ in here I always get 0 !!
while (pCur.moveToNext())
{
String phone = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
Log.d("states","phone" + phone);
}
pCur.close();
}
}
phones.close();
but this code don't give me any numbers at all :(