使用 URI 查询 MediaStore
我正在尝试找到一种通过 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,我已经弄清楚了这一点。这是我想要的信息的链接:
http://developer.android .com/guide/topics/providers/content-providers.html
以下是完成此操作的代码:
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:
没有必要为一栏获取所有内容。试试这个:
There's no need to get everything for one column. Try this: