【问题标题】:How to convert a file:// uri into content:// uri?如何将 file:// uri 转换为 content:// uri?
【发布时间】:2012-02-05 16:36:38
【问题描述】:

我发现在我的设备上,如果我有一个 uri,默认媒体显示工具不会向我显示相同的内容:

file://mnt/sdcard/DCIM/Image.jpg

当我通过内置意图选择图像时,我得到这个:

content://media/external/images/media/247 

这两个都显示同一个文件,但是当我使用第一个时,我没有任何共享选项。

我的问题是,如何在给定文件 Uri 的情况下找到内容 Uri?

【问题讨论】:

  • 我有相反的问题——我有来自 insertImage 的内容 uri,我需要一个 File-url。
  • @Richard 将其作为一个新问题提出,否则您只会引起我的注意。
  • 谢谢;通过进一步搜索找到它。

标签: android uri


【解决方案1】:

我正在制作文件,所以我有一个File 对象file

所以我现在这样做是为了获取文件的 Uri 作为“content://”Uri。

Uri capturedImage = Uri.parse(
      android.provider.MediaStore.Images.Media.insertImage(
      getContentResolver(),
      file.getAbsolutePath(), null, null));

感谢回答这个问题How can I capture an image in Android and have it show up in the gallery?

【讨论】:

  • @tejshah 习惯上点击灰色的向上箭头表示感谢有用的答案:)
猜你喜欢
  • 2014-07-15
  • 2016-02-13
  • 2016-01-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多