如何获得短信URI中的联系人的显示名称? [英] How to get the contact's display name in sms uri?

查看:230
本文介绍了如何获得短信URI中的联系人的显示名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从SMS URI得到联系人的显示名称。我应该得到的人的接触ID,如果那人却在我的联系人列表。但每次我有一个空的,这意味着该人是不是在我的联系人列表中的响应。但实际上人在我的联系人列表和消息中显示。那么,有没有办法从手机短信URI得到人的显示名称?顺便说一句,我使用的2.2模拟器。


解决方案

 乌里personUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI,smsMsg.getOriginatingAddress());CUR = appContext.getContentResolver()查询(personUri,新的String [] {} PhoneLookup.DISPLAY_NAME,NULL,NULL,NULL);如果(cur.moveToFirst()){
             INT nameIndex = cur.getColumnIndex(PhoneLookup.DISPLAY_NAME);             PersonName的= cur.getString(nameIndex);
}
cur.close();

I am trying to get the contact's display name from the sms uri. I should get the person's contact id if that person is in my contact list. But every time I got a Null as a respond which means the person is not in my contact list. But actually the person is in my contact list and shown in the message. So is there a way to get the person's display name from sms uri?btw, I am using 2.2 emulator.

解决方案

Uri personUri = Uri.withAppendedPath( ContactsContract.PhoneLookup.CONTENT_FILTER_URI, smsMsg.getOriginatingAddress());  

cur = appContext.getContentResolver().query(personUri, new String[] { PhoneLookup.DISPLAY_NAME }, null, null, null );  

if( cur.moveToFirst() ) {  
             int nameIndex = cur.getColumnIndex(PhoneLookup.DISPLAY_NAME);  

             PersonName = cur.getString(nameIndex); 
}
cur.close();

这篇关于如何获得短信URI中的联系人的显示名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆