阅读约会后收到的短信 [英] Reading sms received after a date
本文介绍了阅读约会后收到的短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试阅读约会后收到的所有短信.
I'm trying to read all the sms I received after a date.
代码如下:
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
这会返回一个空光标.
当我执行这段代码时:
Cursor cursor = context.getContentResolver().query( SMS_INBOX_CONTENT_URI, new String[] { "_id" }, "read=1", null, null);
把所有的短信都给我了.
Was returning me all the sms.
有人知道如何按日期过滤短信吗?
Somebody knows how to filter the sms by date?
我也尝试在发送短信中执行,但遇到了同样的问题.
I tried to execute in the send sms too, but had the same problem.
推荐答案
我使用以下代码在特定日期后检索短信.
I use following code to retrieve sms messages after a particular date.
// 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();
从 http://realembed.blogspot.com/2013/11/retrieve-sms-message-on-particular-date.html
这篇关于阅读约会后收到的短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文