2012-08-14 104 views
4

我正在开发一个短信应用程序。在我的应用程序,我必须列出所有的convrsation.SO我使用以下Uri。Android短信阅读数

content://mms-sms/conversations/ 

其工作正常。以下是我的代码片段。

Uri uri = Uri.parse("content://mms-sms/conversations/"); 
Cursor c= getContentResolver().query(uri, null, null ,null,null); 
startManagingCursor(c); 
if(c.moveToFirst()){ 

      for(int i=0;i<c.getCount();i++){ 
        body[i]= c.getString(c.getColumnIndexOrThrow("body")).toString(); 
        number[i]=c.getString(c.getColumnIndexOrThrow("address")).toString(); 
        c.moveToNext(); 
      } 
    } 
    c.close(); 

    for (int i = 0; i < body.length; i++) { 
     System.out.println("body ="+body[i]); 
     System.out.println("number ="+number[i]); 
    } 

该号码打印每个对话号码和正文打印每个对话的最后一条消息。但我想要获得每个对话整个消息,并帮助我讨论具体的数字。

回答

1

Conversations游标,您可以获得thread_id。一旦你得到了thread_id,从sms provider继续查询返回具有相同thread_id

例如,所有消息:thread_id = 2

Uri SMS_INBOX = Uri.parse("content://sms"); 
Cursor c = getContentResolver().query(SMS_INBOX, null, "thread_id" + " = " 
       + "2", null, 
       "date" + " ASC"); 


while (c.moveToNext()){ 

     Log.v("BODY", c.getString(11).toString()); // 11 is the index of body with project URI 

    } 
+0

@Yui。非常感谢 。 – sarath 2012-08-14 09:02:46

+0

我如何才能使用SMS和MMS? – Pkmmte 2013-10-10 02:52:50

+0

@Pkmmte:更改URI。你可以在SO上搜索。对不起,我一直没有与Android的工作,所以我不记得 – 2013-10-10 10:27:36