I am trying to fetch the E Mail address of A Contact. I found How to get contact email id? but I could not use this.
I have written following Code to fetch Email
Cursor c1;
c1 = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, ContactsContract.Contacts.DISPLAY_NAME);
if(c1==null)
return;
if(c1.getCount() > 0)
{
while(c1.moveToNext())
{
String id = c1.getString(c1.getColumnIndex(Contacts._ID));
if(id==null)
continue;
Cursor email_crsr = getContentResolver().query(CommonDataKinds.Email.CONTENT_URI, null, CommonDataKinds.Phone.CONTACT_ID +" = ?", new String[]{id}, null);
if(email_crsr!=null)
email = phone_crsr.getString(phone_crsr.getColumnIndex(CommonDataKinds.Email.DATA));
}
}
I am following Exception : 04-09 10:38:59.487: E/AndroidRuntime(8150): Caused by: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 4