I want to fetch name of a contact by its id.My code as below:
public void Get_Contact_Name(String id)
{
String[] projection = new String[]
{ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME,
ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME,
ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME,
ContactsContract.CommonDataKinds.StructuredName.SUFFIX,
ContactsContract.CommonDataKinds.StructuredName.PREFIX,
ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME};
String where = ContactsContract.Data.CONTACT_ID + " = ? AND " +
ContactsContract.Data.MIMETYPE + " = ?";
String[] whereParameters = new String[]{id,
ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE};
Cursor contacts =
contentresolver.query(ContactsContract.Data.CONTENT_URI, projection,
where, whereParameters, null);
if (contacts.moveToFirst()) {
display_name =
Null_check((contacts.getString(contacts.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME))));
given_name =
Null_check((contacts.getString(contacts.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME))));
suffix_name =
Null_check((contacts.getString(contacts.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.SUFFIX))));
prefix_name =
Null_check((contacts.getString(contacts.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.PREFIX))));
middle_name =
Null_check((contacts.getString(contacts.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME))));
family_name =
Null_check((contacts.getString(contacts.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME))));
}
contacts.close();
}
it gives error.Can anyone tell me whats the wrong?
Thanks in advance.
Regards
riskycoder
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en