2012-02-18 43 views
1

當我查詢「content:// sms /」內容提供者並從地址欄中提取信息時;我總是收到郵件是「從」或「發送給」的電話號碼。如果我收到一條消息,則地址是來自其他人的電話號碼。當我發送消息時,地址就是我發送的消息。內容://短信/地址欄不總是返回「發件人」號碼

如何區分「content:// sms /」文件夾中的郵件是發送郵件還是收到郵件而不查詢相應的收件箱/發送文件夾?

Uri uri = Uri.parse("content://sms/"); 
    String[] columns = new String[] { "_id", "thread_id", "address", "person", "date", "body" }; 
    String selection = "thread_id = " + threadId; 
    String sortOrder = "date DESC"; 
    String limit = "LIMIT " + String.valueOf(mItemsOnPage); 

    TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); 
    String deviceNumber = tm.getLine1Number(); 

    Cursor cursor = getContentResolver().query(uri, columns, selection, null, 
      sortOrder + " " + limit); 

    if (cursor != null) { 
     cursor.moveToLast(); 

     while (!cursor.isBeforeFirst()) { 
      long messageId = cursor.getLong(0); 
      String address = cursor.getString(2); 
      long date = cursor.getLong(4); 
      String body = cursor.getString(5); 
      long person = cursor.getLong(3); 
      cursor.moveToPrevious(); 
     } 
    } 
    cursor.close(); 

回答

3

您需要在查詢中包含列type。它包含一個,指示您是處理收到的(type == 1)還是發送的(type == 2)消息。

這樣你就會知道如何解釋地址欄。

+0

我意識到此列,但認爲這將MMS和SMS區分。非常感謝。 – Justin 2012-02-18 17:44:52

+0

你會碰巧知道第5類消息是什麼嗎? – Justin 2012-02-20 19:48:17

+1

@Justin請參閱:https://developer.android.com/reference/android/provider/Telephony.TextBasedSmsColumns.html#MESSAGE_TYPE_ALL所有相關的常量 – Ben 2015-09-29 08:39:07

-2

5型似乎是一個草稿郵件類型(三星i9100至少)

0
public static final Uri SMS_Inbox = Uri.parse("content://sms/inbox"); 
public static final Uri SMS_Sent = Uri.parse("content://sms/sent"); 
public static final Uri SMS_draft = Uri.parse("content://sms/draft"); 
public static final Uri SMS_Queued = Uri.parse("content://sms/queued"); 
public static final Uri SMS_ALL = Uri.parse("content://sms/"); 

public static final int INBOX = 1; 
public static final int SEND = 2; 
public static final int DRAFT = 3; 
public static final int QUEUED = 6; 
相關問題