【问题标题】:Trying to select image from gallery on a different user profile尝试从不同用户配置文件的图库中选择图像
【发布时间】:2020-03-18 00:33:58
【问题描述】:

我们目前正在开发一个在托管设备企业环境中运行的 android 应用程序。

现在我们尝试使用以下代码通过 Intent 选择图像:

val galleryPickerIntent = Intent(Intent.ACTION_PICK)
galleryPickerIntent.type = "image/*"
galleryPickerIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)

fragment.startActivityForResult(galleryPickerIntent, SELECT_IMAGES_INTENT_RESULT)

之后,我们通过 contentResolver 处理来自 intent.clipData 的图像,它为我们提供如下 URL:/storage/emulated/0/DCIM/Camera/IMG_20200130_113056.jpg

当我们尝试从其他配置文件访问此 URL 时,例如,该应用正在工作配置文件中运行,但用于选择的图库应用位于私人配置文件中,然后尝试访问此图像 URL 将导致访问被拒绝异常。

有没有合适的方法来解决这个问题?理想情况下,我们会允许将工作资料和私人应用程序用于图像选择。

【问题讨论】:

    标签: android kotlin android-intent android-gallery android-contentresolver


    【解决方案1】:

    我找到了答案,我们正在错误地解析图像。我们从 uri 中提取了 filePath,而不是直接在其上使用 contentResolver.openInputStream 解决了我们的问题。

    【讨论】:

      猜你喜欢
      • 2020-02-07
      • 2016-12-30
      • 1970-01-01
      • 1970-01-01
      • 2018-01-17
      • 1970-01-01
      • 1970-01-01
      • 2021-01-10
      • 1970-01-01
      相关资源
      最近更新 更多