D
Deleted member 103
Guest
Hi,
I try with this code, the name and last name of a contact to get, unfortunately it does not work. Can someone tell me why?
Ciao,
Filippo
I try with this code, the name and last name of a contact to get, unfortunately it does not work. Can someone tell me why?
B4X:
public String[] getFirstNameLastName(String id)
{
String[] retValue = new String[3];
retValue[0] = "";
retValue[1] = "";
retValue[2] = "";
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};
ContentResolver cr = this.m_ba.context.getContentResolver();
Cursor contacts = cr.query(ContactsContract.Data.CONTENT_URI, projection, where, whereParameters, null);
if (contacts.moveToFirst())
{
Log.d("Log_Tag","ID=" + id);
retValue[2] = contacts.getString(contacts.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME));
retValue[0] = contacts.getString(contacts.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME));
//String suffix_name = contacts.getString(contacts.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.SUFFIX));
//String prefix_name = contacts.getString(contacts.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.PREFIX));
//String middle_name = contacts.getString(contacts.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME));
retValue[1] = contacts.getString(contacts.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME));
}
contacts.close();
return retValue;
}
Ciao,
Filippo