Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

retrieve contact's nickname

I want to get the nickname of a contact from addressbook. I start with his phone number, query it and want the nickname (aka alias) as a result.

Cursor cur = context.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.NUMBER + " = " + incomingNumber, null, null);

        if (cur.moveToFirst()) {
            Log.e("saymyname", cur.getString(cur.getColumnIndex(ContactsContract.CommonDataKinds.Nickname.NAME)));
            Log.e("saymyname", cur.getString(cur.getColumnIndex(ContactsContract.CommonDataKinds.Nickname.LABEL)));
        }

Output of the logs is the incomingNumber (first Log.e() ) and null (second Log.e() ), but I want to get the contact's nickname!

Thanks Tom

like image 671
TomTasche Avatar asked Feb 26 '23 20:02

TomTasche


1 Answers

Nickname is held in a different table than the phone numbers, you have to query ContactsContract.Data.CONTENT_URI

Check my answer on this question

like image 109
Pentium10 Avatar answered Mar 07 '23 22:03

Pentium10