gpt4 book ai didi

android - 权限拒绝:阅读android.support.v4.content.FileProvider uri ANDROID饼图

转载 作者:行者123 更新时间:2023-12-02 13:44:43 24 4
gpt4 key购买 nike

我无法共享屏幕图像,它在旧版本中运行良好,只是在android pie上不起作用,我收到此错误,有人可以帮我吗?

错误

java.lang.SecurityException: Permission Denial: reading android.support.v4.content.FileProvider uri content://myapp.com.provider/external/screenshot.png from pid=29478, uid=1000 requires the provider be exported, or grantUriPermission()


  fun shareIt(imagePath: File? = this.imagePath) {

val uri = FileProvider.getUriForFile(context!!, BuildConfig.APPLICATION_ID+ ".provider", imagePath!!)

val sharingIntent = Intent(Intent.ACTION_SEND)
sharingIntent.type = "image/*"
val shareBody = "APP"
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "app share")
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody)
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri)

startActivity(Intent.createChooser(sharingIntent, "SHARE VIA"))
}

list 代码
  <provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/paths" />
</provider>

路径代码:
<paths>
<external-path name="external" path="." />
<external-files-path name="external_files" path="." />
<cache-path name="cache" path="." />
<external-cache-path name="external_cache" path="." />
<files-path name="files" path="." />
</paths>

有谁知道我该怎么做才能解决这个问题?欢迎任何帮助。

最佳答案

就像错误消息一样:

  • 您必须设置android:exported="true"(将公开它)或
  • ,您必须在其上使用方法grantUriPermission()(授予访问权限)。

  • 建议从已弃用的 android.support.v4.content.FileProvider 迁移到 androidx.core.content.FileProvider

    关于android - 权限拒绝:阅读android.support.v4.content.FileProvider uri ANDROID饼图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59914861/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com