2016-08-16 94 views
0

我正在開發一個針對android的短信應用程序,我需要閱讀發件人和收件人之間的對話。在Android中閱讀短信會話

我試過了解我所知道的一切,但仍然無法做到。

Cursor c = getContentResolver(),query(Uri.parse("content://mms-sms/conversations?simple=true"), null,null,null,null); 

上面的代碼沒有給出兩個人之間的對話。 請幫助我如何閱讀對話。

回答

0

我曾經用這樣的代碼,但不記得在那裏我得到它:

StringBuilder smsBuilder = new StringBuilder(); 
    final String SMS_URI_INBOX = "content://sms/inbox"; 
    final String SMS_URI_ALL = "content://sms/"; 
    try { 
     Uri uri = Uri.parse(SMS_URI_INBOX); 
     String[] projection = new String[]{"_id", "address", "person", "body", "date", "type"}; 
     Cursor cur = getActivity().getContentResolver().query(uri, projection, "address='33300'", null, "date desc"); 


     int index_Address = cur.getColumnIndex("address"); 
     int index_Person = cur.getColumnIndex("person"); 
     int index_Body = cur.getColumnIndex("body"); 
     int index_Date = cur.getColumnIndex("date"); 
     int index_Type = cur.getColumnIndex("type"); 
     String strAddress = cur.getString(index_Address); 
     int intPerson = cur.getInt(index_Person); 
     String strbody = cur.getString(index_Body); 
     long longDate = cur.getLong(index_Date); 
     int int_Type = cur.getInt(index_Type); 

     smsBuilder.append("[ "); 
     smsBuilder.append(strAddress + ", "); 
     smsBuilder.append(intPerson + ", "); 
     smsBuilder.append(strbody + ", "); 
     smsBuilder.append(longDate + ", "); 
     smsBuilder.append(int_Type); 
     smsBuilder.append(" ]\n\n"); 

     cur.close(); 
+0

也許這將是使用到u的。它讀取所有來自33300號碼的短信 – Manny265

+0

我使用該代碼,它只給我發送給我的短信,但不是完整的對話。我真正想要的是發件人和我之間的完整對話。 –

+0

我使用該代碼,它只給我發送給我的短信,但不是完整的對話。我真正想要的是發件人和我之間的完整對話。 –