我如何在Android中获取所有outbox短信和mms?

时间:2016-12-27 06:50:14

标签: android

我可以获取外发短信或彩信,但无法获取最新的短信或彩信。

        Uri draftURI = Uri.parse("content://sms/sent");

        // List required columns
        String[] reqCols = new String[]{"_id", "address", "body"};

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

        // Fetch Sent SMS Message from Built-in Content Provider
        Cursor c = cr.query(draftURI, reqCols, null, null, null);

我甚至使用Uri draftURI = Uri.parse("content://sms");但没有帮助。

1 个答案:

答案 0 :(得分:0)

检查

Uri sentURI = Uri.parse("content://sms/sent");
String[] reqCols = new String[] { "_id", "address", "body" };
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(sentURI, reqCols, null, null, null);

if (cursor.moveToFirst()) { 
    do {
       String msgData = "";
       for(int idx=0;idx<cursor.getColumnCount();idx++)
       {
           msgData += " " + cursor.getColumnName(idx) + ":" + cursor.getString(idx);
       }
       Log.d("Msg",msgData);
    } while (cursor.moveToNext());
}