gpt4 book ai didi

android - 如何从 Android Q 中的媒体商店获取专辑?

转载 作者:行者123 更新时间:2023-12-04 12:59:28 31 4
gpt4 key购买 nike

我正在尝试从媒体商店获取图像和视频(专辑明智)。它在操作系统版本 < 10 的设备中正常工作。在 Android Q 中,我收到语法错误。

System.err: android.database.sqlite.SQLiteException: near "GROUP": syntax error (code 1 SQLITE_ERROR): , while compiling: SELECT _id, _data, date_modified, bucket_display_name, media_type FROM files WHERE ((is_pending=0) AND (is_trashed=0) AND (volume_name IN ( 'external_primary' ))) AND ((media_type=1 OR media_type=3) GROUP BY (bucket_display_name)) ORDER BY bucket_display_name ASC

我正在使用下面的代码来获取数据。
 Uri queryUri = MediaStore.Files.getContentUri("external");
Uri intqueryUri = MediaStore.Files.getContentUri("internal");

String[] projection = {MediaStore.Images.Media._ID,
MediaStore.MediaColumns.DATA,
MediaStore.MediaColumns.DATE_MODIFIED,
MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
MediaStore.Files.FileColumns.MEDIA_TYPE};

// Return only video and image metadata.
String selection;



selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "="
+ MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE
+ " OR "
+ MediaStore.Files.FileColumns.MEDIA_TYPE + "="
+ MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO;


Cursor cursorExternal,cursorInternal;

cursorExternal = getContentResolver().query(queryUri, projection, selection+") GROUP BY (bucket_display_name",
null, MediaStore.Images.Media.BUCKET_DISPLAY_NAME+" ASC");
cursorInternal = getContentResolver().query(intqueryUri, projection, selection+") GROUP BY (bucket_display_name",
null, MediaStore.Images.Media.BUCKET_DISPLAY_NAME+" ASC");



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));

Log.w( "album:** ",album+"" );

HashMap<String, String> listData = Function.mappingInboxAlbum(album, path, countPhoto);

if (!albumList.contains(listData)) {

albumList.add(listData);
}


}
cursor.close();

我用谷歌搜索但没有得到任何解决方案。
请帮忙...

最佳答案

在 AndroidManifest 中添加这一行:

android:requestLegacyExternalStorage="true"

关于android - 如何从 Android Q 中的媒体商店获取专辑?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60407263/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com