使用 URI 查询 MediaStore

发布于 2024-11-23 21:04:53 字数 793 浏览 3 评论 0原文

我正在尝试找到一种通过 uri 查询媒体存储中的单个文件的方法。我有一个 uri 列表,我想在我的应用程序中提供附加信息。

例如: content://media/external/audio/media/10

file:///sdcard/media/audio/sample.mp3

这是我正在处理的代码。我不确定 id 应该是什么?

        String[] cols = new String[] {
                MediaStore.Audio.Media._ID,
                MediaStore.Audio.Media.DATA,
                MediaStore.Audio.Media.TITLE
        };


        String where = MediaStore.Audio.Media._ID + "=" + id;

        String[] proj = { MediaStore.Audio.Media._ID, MediaStore.Audio.Media.DATA, MediaStore.Audio.Media.DISPLAY_NAME, MediaStore.Video.Media.SIZE, MediaStore.Audio.Media.ALBUM };

        Cursor musiccursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, proj, null, cols, null);

提前致谢。

I'm trying to find a way to query the mediastore for individual files via a uri. I have a list of uris, for which I would like to provide additional info in my app.

Such as:
content://media/external/audio/media/10

or

file:///sdcard/media/audio/sample.mp3

Here's the code I'm working around. I'm not sure what id should be?

        String[] cols = new String[] {
                MediaStore.Audio.Media._ID,
                MediaStore.Audio.Media.DATA,
                MediaStore.Audio.Media.TITLE
        };


        String where = MediaStore.Audio.Media._ID + "=" + id;

        String[] proj = { MediaStore.Audio.Media._ID, MediaStore.Audio.Media.DATA, MediaStore.Audio.Media.DISPLAY_NAME, MediaStore.Video.Media.SIZE, MediaStore.Audio.Media.ALBUM };

        Cursor musiccursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, proj, null, cols, null);

Thanks in advance.

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

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

发布评论

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

评论(2

娜些时光,永不杰束 2024-11-30 21:04:53

好吧,我已经弄清楚了这一点。这是我想要的信息的链接:

http://developer.android .com/guide/topics/providers/content-providers.html

以下是完成此操作的代码:

Uri uri = Uri.parse("content://media/external/audio/media/10");
Cursor musiccursor = managedQuery(uri, null, null, null, null);

if (musiccursor.moveToFirst()) {
    String title; 
    int titleColumn = musiccursor.getColumnIndex(MediaStore.Audio.Media.TITLE); 
    title = musiccursor.getString(titleColumn);
}   

Alright, I figured this one out. Here's a link to the info I was after:

http://developer.android.com/guide/topics/providers/content-providers.html

And here's the code that gets it done:

Uri uri = Uri.parse("content://media/external/audio/media/10");
Cursor musiccursor = managedQuery(uri, null, null, null, null);

if (musiccursor.moveToFirst()) {
    String title; 
    int titleColumn = musiccursor.getColumnIndex(MediaStore.Audio.Media.TITLE); 
    title = musiccursor.getString(titleColumn);
}   
〆凄凉。 2024-11-30 21:04:53

没有必要为一栏获取所有内容。试试这个:

Uri uri = Uri.parse("content://media/external/audio/media/10");
String[] columns = new String[] {MediaStore.Audio.Media.TITLE};
Cursor musiccursor = managedQuery(uri, columns, null, null, null);

if (musiccursor.moveToFirst()) {
    String title = musiccursor.getString(0);
}   

There's no need to get everything for one column. Try this:

Uri uri = Uri.parse("content://media/external/audio/media/10");
String[] columns = new String[] {MediaStore.Audio.Media.TITLE};
Cursor musiccursor = managedQuery(uri, columns, null, null, null);

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