I've been trying to get the nickname of a contact for a few hours now, and still cant get them to work, I've been told that they are in a differnt table to the phone numbers etc.. But i dont know how to access them.
The closest I've got is this..
Cursor cursor = context.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, ContactsContract.Contacts._ID +" = ?", new String[]{String.valueOf(recordId)}, null);
while (cursor.moveToNext()) {
Cursor nickname = context.getContentResolver().query( ContactsContract.Data.CONTENT_URI, null, ContactsContract.CommonDataKinds.Nickname.CONTACT_ID +" = "+ recordId, null, null);
while (nickname.moveToNext()) {
try {
String nicknameName = nickname.getString(nickname.getColumnIndex(ContactsContract.CommonDataKinds.Nickname.NAME));
String nicknameType = nickname.getString(nickname.getColumnIndex(ContactsContract.CommonDataKinds.Nickname.TYPE));
switch (Integer.valueOf(nicknameType)) {
case 1: nicknameType = "TYPE_HOME"; break;
}
list.add(new KeyValue("Nickname:" + nicknameType, nicknameName));
} catch (Exception e) { continue; }
}
nickname.close();
}
This gets all the data of the contact along with the type eg: Thomas Owers
1
this is all good but it doesn't give me what the data is, so it gives the email, phone, names, nickname but i cant distinguish between them.
Any help would be much apreciated, Thank you! :)