2011-08-30 91 views
0

我可以阅读短信收件箱并显示所有消息。我有两个问题。第一个是人字段始终为NULL。Android 2.2阅读短信收件箱消息

这是我对“content:// sms/inbox”的查询。

Cursor cursor = context.getContentResolver().query(SMS_INBOX_CONTENT_URI, 
      new String[] { "_id", "thread_id", "address", "person", "date", "body" }, 
        null, 
        null, 
        SORT_ORDER); 

人字段始终为NULL。有没有办法检索此短信的实际显示名称?是否有连接到另一个表来检索显示名称?

其次,当我在我的手机上进行测试时,我注意到我的短信未包含在查询中。为什么?有没有可能解决这个问题?

在此先感谢。

回答

0
The person field is always NULL. Is there a way to retrieve the actual display name for 


this SMS message? Is there a join to another table to retrieve display name? 

对于显示名称必须使用另一个查询和光标,或者你可以加入查询获取的人的名字,但有时因为那个人接触不会被保存在您的联系人列表或你没有得到名称任何其他组织或公司都会发送邮件,那么您没有获得该名称,因此当时可以在联系人表上查询以获取名称(如果找到),则可以显示该名称,否则将地址显示为默认地址。

在这你明白我的是发件人地址为数字格式,所以你需要传递的联络查询该号码检索人

+0

是刚刚意识到这一点。我将不得不为联系人做另一个查询。同样可以查看我发送的SMS消息,可能会查询已发送的内容存储而不是收件箱。我是Android新手,因此仍然习惯于这些内容商店。谢谢。 – Marquinio

0

的名称试试这个代码地址:

public String findNameByAddress(Context ct,String addr) 
     { 
      Uri myPerson = Uri.withAppendedPath(ContactsContract.CommonDataKinds.Phone.CONTENT_FILTER_URI, 
         Uri.encode(addr)); 

      String[] projection = new String[] { ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME }; 

       Cursor cursor = ct.getContentResolver().query(myPerson, 
         projection, null, null, null); 

       if (cursor.moveToFirst()) { 



        String name=cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)); 


        Log.e("","Found contact name"); 

        cursor.close(); 

        return name; 
       } 

       cursor.close(); 
       Log.e("","Not Found contact name"); 

       return addr; 
     }