检索联系​​人的昵称昵称

2023-09-05 02:30:24 作者:像一座围城

我想从地址簿中的联系人的昵称。我开始与他的电话号码,查询它,并希望昵称(又名化名)结果。

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)));
        }

日志的输出是incomingNumber(第一Log.e())和空(第二Log.e()),但我想要得到的联系人的昵称!

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

谢谢 汤姆

推荐答案

昵称是在一个不同的表比手机号码持有,​​你要查询 ContactsContract.Data.CONTENT_URI

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

检查我对这个答案question

 
精彩推荐
图片推荐