我正在使用MediaStore获取所有的图像相册,它在Android之前运行良好,但是今天我将编译版本提高到了29,它抛出了这个异常:
android.database.sqlite.SQLiteException: near "GROUP": syntax error (code 1 SQLITE_ERROR): , while compiling: SELECT bucket_id, bucket_display_name, mime_type FROM images WHERE ((is_pending=0) AND (is_trashed=0) AND (volume_name IN ( 'external_primary' ))) AND ( GROUP BY bucket_id )下面是我的查询MediaStore的代码:
String[] PROJECTION_BUCKET = {
MediaStore.Images.ImageColumns.BUCKET_ID,
MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME,
MediaStore.Images.ImageColumns.MIME_TYPE};
String BUCKET_GROUP_BY = "1) GROUP BY 1,(2";
String BUCKET_ORDER_BY = "MAX(datetaken) DESC";
Cursor cur = context.getContentResolver().query(getUriOfType(type),
PROJECTION_BUCKET,
BUCKET_GROUP_BY,
null,
BUCKET_ORDER_BY);因为集团不在Android Q中工作。
有什么解决办法吗?
发布于 2020-04-21 18:45:42
的团队不再在android 10(Q)上工作,也不计算。下面的代码片段可能会对您有所帮助。
String path = null;
String album = null;
String timestamp = null;
String countPhoto = null;
Uri uriExternal = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
Uri uriInternal = android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI;
String[] projection = {
MediaStore.MediaColumns.DATA,
MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
MediaStore.MediaColumns.DATE_MODIFIED
};
Cursor cursorExternal = getContentResolver().query(uriExternal, projection, "_data IS NOT NULL", null, null);
Cursor cursorInternal = getContentResolver().query(uriInternal, projection, "_data IS NOT NULL", null, null);
Cursor cursor = new MergeCursor(new Cursor[]{cursorExternal, cursorInternal});
while(cursor.moveToNext()){
path = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA));
album = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.BUCKET_DISPLAY_NAME));
timestamp = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATE_MODIFIED));
countPhoto = Function.getCount(getApplicationContext(), album);
albumOrPhotoList.add(Function.mappingInbox(album, path, timestamp, Function.converToTime(timestamp), countPhoto));
}
cursor.close();
Collections.sort(albumOrPhotoList,new
// Arranging photo album by timestamp decending
MapComparator(Function.KEY_TIMESTAMP, "dsc")); https://stackoverflow.com/questions/56823336
复制相似问题