I am trying to get a contact nickname for several hours and still cannot get them to work, they told me that they are in the differt table by phone numbers, etc. But I do not know how to access them.
The closest I have is ...
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 contact data along with the type eg: Thomas Owers 1 , it's all good, but it does not give me the data, so it gives the email address, phone number, names, nickname but I can not distinguish between them.
Any help would be greatly appreciated, thanks! :)
Tom o source share