读取日期后收到的短信

jon*_*nrz 1 sms android uri

我正在尝试阅读约会后收到的所有短信.

这是代码:

Uri SMS_CONTENT_URI = Uri.parse("content://sms");  
Uri SMS_INBOX_CONTENT_URI = Uri.withAppendedPath(SMS_CONTENT_URI, "inbox");

Cursor cursor = context.getContentResolver().query( SMS_INBOX_CONTENT_URI, new String[] { "_id" }, "date>=61291393200000", null, null);  
//61291393200000 = 03/01/12
Run Code Online (Sandbox Code Playgroud)

这会返回一个空光标.

当我执行此代码时:

Cursor cursor = context.getContentResolver().query( SMS_INBOX_CONTENT_URI, new String[] { "_id" }, "read=1", null, null);
Run Code Online (Sandbox Code Playgroud)

把我所有的短信归还给我.

有人知道如何按日期过滤短信吗?

我试图在发送短信执行,但有同样的问题.

小智 8

我使用以下代码在特定日期之后检索短信.

// First select the date shown by the datepicker.
// Here I am assuming that a DatePicker object is already created with id dpResult
// to select a particular date.
DatePicker datePicker = (DatePicker) findViewById(R.id.dpResult);


// Now create a SimpleDateFormat object.        
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");

// Add 1 in month as its 0 based indexing in datePicker but not in SimpleDateFormat
String selectedDate = datePicker.getYear() + "-" +  (datePicker.getMonth() + 1) + "-" +    datePicker.getDayOfMonth();

// Now create a start time for this date in order to setup the filter.
Date dateStart = formatter.parse(selectedDate + "T00:00:00");

// Now create the filter and query the messages.
String filter = "date>=" + dateStart.getTime();
final Uri SMS_INBOX = Uri.parse("content://sms/inbox");
Cursor cursor = getContentResolver().query(SMS_INBOX, null, filter, null, null);

while(cursor.moveToNext()) {

    // Perform the required stuff here.             
}
cursor.close();
Run Code Online (Sandbox Code Playgroud)

http://realembed.blogspot.com/2013/11/retrieve-sms-message-on-particular-date.html获得上面的代码片段