使用Telephony.SMS访问已发送SMS的联系人姓名

时间:2015-09-03 12:40:39

标签: android

我希望获取SMS收件箱的简单信息,即联系人姓名和邮件正文。

我能够获取正文,但联系人姓名为空白。

以下是代码段

        String[] reqCols = new String[] { Telephony.Sms.Inbox._ID, Telephony.Sms.Inbox.PERSON, Telephony.Sms.Inbox.BODY };

        // Get Content Resolver object, which will deal with Content Provider
        ContentResolver cr = getContentResolver();

        // Fetch Inbox SMS Message from Built-in Content Provider
        Cursor c = cr.query(Telephony.Sms.Inbox.CONTENT_URI, reqCols, null, null, null);

        // Attached Cursor with adapter and display in listview
        adapter = new SimpleCursorAdapter(this, R.layout.row, c,
                new String[] { Telephony.Sms.Inbox.BODY, Telephony.Sms.Inbox.PERSON}, new int[] {
                R.id.lblMsg, R.id.lblNumber });
        lvMsg.setAdapter(adapter); 

在我的listview中,我可以显示消息正文,但不能显示联系人姓名。

请注意,如果我改为使用“.ADDRESS”,则会成功显示联系号码。

有任何帮助吗?我已经拥有“READ_CONTACTS”权限。

编辑:我能想到解决这个问题的唯一方法是使用ContactsContract.PhoneLookup并使用电话号码查找联系人姓名。这似乎是一个需要太长时间的必要步骤。没有人有更好的解决方案?

0 个答案:

没有答案
相关问题