Anu*_*nuj 3 android android-contentresolver
如何MediaStore.Images.Media.EXTERNAL_CONTENT_URI在两个日期之间查询内容解析器()?我正在尝试使用代码,但这不起作用.
Calendar c = Calendar.getInstance()
Date date2 = c.getTime();
c.add(Calendar.YEAR,-1);
Date date1 = c.getTime();
Cursor cursor = getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
projection,
MediaStore.MediaColumns.DATE_ADDED + ">=? and "+MediaStore.MediaColumns.DATE_ADDED +"<=?",
new String[]{"" + date1,""+date2},
MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC");
Run Code Online (Sandbox Code Playgroud)
从此MediaColumns.DATE_ADDED日期时间以长格式.
为此,您需要传递long数据而不是Date对象
更改您的查询
Cursor cursor = getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
projection,
MediaStore.MediaColumns.DATE_ADDED + ">=? and "+MediaStore.MediaColumns.DATE_ADDED +"<=?",
new String[]{"" + date1,""+date2},
MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC");
Run Code Online (Sandbox Code Playgroud)
成
Cursor cursor = getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
projection,
MediaStore.MediaColumns.DATE_ADDED + ">=? and "+MediaStore.MediaColumns.DATE_ADDED +"<=?",
new String[]{"" + date1.getTtime()/1000,""+date2.getTime()/1000},
MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2213 次 |
| 最近记录: |