我知道这是一个很古老的问题,我只是偶然发现了一个没有答案的问题。所以请不要因为这个就轻视我。也许有人需要这个答案。
你所要做的就是查询电话内容提供商(我用过
CallLog.Calls
用常量代替列名的硬编码字符串)
String[] projection = { CallLog.Calls.DATE };
Uri smsContentUri = Uri.parse("content://sms/");
Cursor cursor = this.getContentResolver().query(smsContentUri , selection,where, null, null);
SimpleDateFormat format = new SimpleDateFormat("dd-MM-yy");
cursor.moveToFirst();
Log.d("SMS COUNT", ""+cursor.getCount());
while(cursor.isAfterLast() == false){
Log.d("SMS DATE", ""+cursor.getString(cursor.getColumnIndex(CallLog.Calls.DATE))); //raw format of the date in milliseconds
long callDate = cursor.getLong(cursor.getColumnIndex(CallLog.Calls.DATE));
String dateString = format.format(new Date(callDate));
Log.i("SMS DATE",dateString);
cursor.moveToNext();
}
对于您的情况,您所要做的就是提供一个where子句,它将在投影上进行选择。您需要转换前面提到的日期的界限(以毫秒为单位)(获取日期并将其转换为毫秒)。确保你的模式与
"dd-MM-yy"
.
where子句应该如下所示:
String where = CallLog.Calls.DATE+"<"+FRIST_BOUND_IN_MS + " AND "+ CallLog.Calls.DATE + "< " + SECOND_BOUND_IN_MS;
带我们进入最后一个问题:
SELECT date FROM sms_content WHERE date < 'firstbound' AND date < 'second bound'
修改
Uri smsContentUri = Uri.parse("content://sms/");
添加到
"content://sms/"
要获取的已发送或收件箱
"content://sms/sent"
或
"content://sms/inbox"
,关于要查询的框。
干杯。