从文件路径获取 MediaStore 内容 Uri?
我有一个列出 MediaStore 中所有视频的应用程序。 (我需要内部存储和外部存储)。
基本上我有两个查询 MediaStore.Video.Media.EXTERNAL_CONTENT_URI 和 MediaStore.Video.Media.INTERNAL_CONTENT_URI 的游标。
然后,我使用 MergeCursor 合并这些查询并通过 CursorAdapter 显示在 ListView 中。
问题是,有时我想删除其中一个视频,但我需要“内容 Uri”来执行此操作,因为我没有办法确定所选视频的存储位置。
我有 MediaStore 中视频的完整文件路径和 ID。
如何从文件路径/Uri 中获取“内容 Uri”?
I have an application that lists all videos in MediaStore. (I need both internal storage and external storage).
Basically I have two cursors which query MediaStore.Video.Media.EXTERNAL_CONTENT_URI and MediaStore.Video.Media.INTERNAL_CONTENT_URI.
Then I use a MergeCursor to merge these queries and display in a ListView with a CursorAdapter.
The thing is that sometimes I want to delete one of the videos, but I need the "content Uri" for this operation because I don't have a way to determine the storage of the selected video.
I have the full file path of the Video and the ID in MediaStore.
How can I get the "content Uri" from the file path/Uri?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要回答标题中的问题:
我必须从 URI 获取路径并从我的应用程序中的路径获取 URI。前者:后者
(我为视频所做的,但也可以通过用 MediaStore.Audio(等)代替 MediaStore.Video 来用于音频或文件或其他类型的存储内容):
基本上,
DATAMediaStore
的 code> 列(或您正在查询的任何子部分)存储文件路径,因此您可以使用该信息来查找它。To answer the question in the title:
I have to get the path from URIs and get the URI from paths in my app. The former:
The latter (which I do for videos, but can also be used for Audio or Files or other types of stored content by substituting MediaStore.Audio (etc) for MediaStore.Video):
Basically, the
DATA
column ofMediaStore
(or whichever sub-section of it you're querying) stores the file path, so you use that info to look it up.回答我自己的问题:)
找到了一种简单而简单的(!)方法来查找路径的存储:**
Answering my own question :)
Found an easy and trivial(!) way to find the storage of the path:**