外部的 MediaStore URI?

发布于 2025-01-18 12:39:57 字数 1115 浏览 3 评论 0原文

作为 MediaStore 新手,我不知道这个 uri 有什么问题:

MediaStore.Files.getContentUri("external")

这些 uri 不断返回零。

我的示例代码:

String file = null;
String sortBy = "";
if (filterSort == "time") {
    sortBy = MediaStore.Files.FileColumns.DATE_MODIFIED;
} else if (filterSort == "size") {
    sortBy = MediaStore.Files.FileColumns.SIZE;
}
String[] projection = {MediaStore.Files.FileColumns.DATA};
android.database.Cursor cursor = getContentResolver().query(MediaStore.Files.getContentUri("external"), projection, null, null, sortBy + "DESC");
if (cursor != null) {
    while (cursor.moveToNext()) {
        file = cursor.getString(0);
        states.add(file);
    }
    cursor.close();
}

尝试解决 Uri.parse 有效,但没有应用排序过滤器。回来与 MediaStore.Files.getContentUri("external") ,它不断通过 Android 8.1 设备上的异常向我提供此信息:

android.database.sqlite.SQLiteException:
no such column: date_modifiedDESC (code 1): , while compiling: SELECT _data FROM files WHERE ( invalid=0) ORDER BY date_modifiedDESC

是否有任何方法来解决/更改/执行?

As a MediaStore newbie's, I dunno what's wrong with this uri:

MediaStore.Files.getContentUri("external")

Those uri's keeps returns to zero.

My example codes:

String file = null;
String sortBy = "";
if (filterSort == "time") {
    sortBy = MediaStore.Files.FileColumns.DATE_MODIFIED;
} else if (filterSort == "size") {
    sortBy = MediaStore.Files.FileColumns.SIZE;
}
String[] projection = {MediaStore.Files.FileColumns.DATA};
android.database.Cursor cursor = getContentResolver().query(MediaStore.Files.getContentUri("external"), projection, null, null, sortBy + "DESC");
if (cursor != null) {
    while (cursor.moveToNext()) {
        file = cursor.getString(0);
        states.add(file);
    }
    cursor.close();
}

Trying to solve with
Uri.parse worked but did not apply sorting filter's. Back with
MediaStore.Files.getContentUri("external") , it keeps giving me this via Exception on Android 8.1 devices:

android.database.sqlite.SQLiteException:
no such column: date_modifiedDESC (code 1): , while compiling: SELECT _data FROM files WHERE ( invalid=0) ORDER BY date_modifiedDESC

Is there any way to solve/change/do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半枫 2025-01-25 12:39:57

也不知道 blackapps 指的是什么,因为他没有以任何方式解决这个问题。

有很多 uri,具体取决于您要提取的内容。
例如:

public Uri get_audio_media_uri(){
    Uri uri_to_use = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
        uri_to_use = MediaStore.Audio.Media.getContentUri(MediaStore.VOLUME_EXTERNAL);
    } else {
        uri_to_use = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
    }
    return uri_to_use;
}

或对于艺术家;

public Uri get_audio_artist_uri(){
    Uri uri_to_use = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
        uri_to_use = MediaStore.Audio.Artists.getContentUri(MediaStore.VOLUME_EXTERNAL);
    } else {
        uri_to_use = MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI;
    }
    return uri_to_use;
}

“date_modifiedDESC”部分是导致问题的原因,因为它需要空格“date_modified DESC”

文件表的结构(部分)

我建议您修改您的投影,例如

String projection[];
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.Q) {
    //no _DATA column in Q
    projection = new String[]{
            MediaStore.Audio.Media._ID,
            MediaStore.Audio.Media.ALBUM,
            MediaStore.Audio.Media.TITLE,
            MediaStore.Audio.Media.ARTIST,
            MediaStore.Audio.Media.DURATION,
            MediaStore.Audio.Media.DATE_MODIFIED
    };
} else {
    projection = new String[]{
            MediaStore.Audio.Media._ID,
            MediaStore.Audio.Media.ALBUM,
            MediaStore.Audio.Media.TITLE,
            MediaStore.Audio.Media.ARTIST,
            MediaStore.Audio.Media.DURATION,
            MediaStore.Audio.Media.DATA
            MediaStore.Audio.Media.DATE_MODIFIED
    };
}

而不是MediaStore.Files.FileColumns.DATE_MODIFIED;

Nor sure what blackapps is referring to as he does not address the question in any way.

There are a number of uris, depending what you want to extract.
for example:

public Uri get_audio_media_uri(){
    Uri uri_to_use = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
        uri_to_use = MediaStore.Audio.Media.getContentUri(MediaStore.VOLUME_EXTERNAL);
    } else {
        uri_to_use = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
    }
    return uri_to_use;
}

or for artists;

public Uri get_audio_artist_uri(){
    Uri uri_to_use = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
        uri_to_use = MediaStore.Audio.Artists.getContentUri(MediaStore.VOLUME_EXTERNAL);
    } else {
        uri_to_use = MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI;
    }
    return uri_to_use;
}

the part "date_modifiedDESC" is what causes the issue as it requires a space "date_modified DESC"

structure (part) of files table

I suggest you amend your projection, for example

String projection[];
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.Q) {
    //no _DATA column in Q
    projection = new String[]{
            MediaStore.Audio.Media._ID,
            MediaStore.Audio.Media.ALBUM,
            MediaStore.Audio.Media.TITLE,
            MediaStore.Audio.Media.ARTIST,
            MediaStore.Audio.Media.DURATION,
            MediaStore.Audio.Media.DATE_MODIFIED
    };
} else {
    projection = new String[]{
            MediaStore.Audio.Media._ID,
            MediaStore.Audio.Media.ALBUM,
            MediaStore.Audio.Media.TITLE,
            MediaStore.Audio.Media.ARTIST,
            MediaStore.Audio.Media.DURATION,
            MediaStore.Audio.Media.DATA
            MediaStore.Audio.Media.DATE_MODIFIED
    };
}

instead of MediaStore.Files.FileColumns.DATE_MODIFIED;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文