当前位置: 首页 > 知识库问答 >
问题:

Update app using Intent FileUriExposedException失败[duplicate]

郎祯
2023-03-14
File outputFile = ...;

Intent promptInstall = new Intent(Intent.ACTION_VIEW).setDataAndType(Uri.fromFile(outputFile), "application/vnd.android.package-archive");
promptInstall.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
promptInstall.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
this.context.startActivity(promptInstall);
<provider
    android:name="androidx.core.content.FileProvider"
    android:authorities="${applicationId}.provider"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/provider_paths" />
</provider>
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="downloads" path="."/>
</paths>
android.os.FileUriExposedException: file:///storage/emulated/0/Download/app-release.apk exposed beyond app through Intent.getData()

我环顾了Stackoverflow和google,但没有一个解决方案奏效。我在provider_paths.xml中做错了什么吗?

共有1个答案

劳鹏云
2023-03-14

flag_grant_write_uri_permission,它将授予最终处理请求及其意图的组件权限。

Intent promptInstall = new Intent(Intent.ACTION_VIEW).setDataAndType(Uri.fromFile(outputFile), "application/vnd.android.package-archive");
promptInstall.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
promptInstall.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
this.context.startActivity(promptInstall);

和更改

Uri uri = Uri.fromFile(outputFile);

Uri uri = FileProvider.getUriForFile(MainActivity.this, BuildConfig.APPLICATION_ID + ".provider",outputFile); 
 类似资料:
  • 我尝试运行这个gradle任务(通过gradlew) 它使用cucmber jvm 并收到此错误 当我从cmd中的同一路径运行同一行时: 更新1: 这个cmd在shell控制台中工作: ./构建/发行版/WebLarge测试/bin/WebLargeTests-f html:构建/报告/cucumber/-f json:构建/报告/cucumber/report.json--胶水com.waze.

  • 在两台不同的笔记本电脑上使用maven构建相同的项目。一个是运行良好,一个是显示错误。 状态:两个系统的配置相同。 使用的命令:mvn clean install-DskipTests=true 错误: 我什至尝试删除所有内容,例如再次创建. m2文件夹。

  • 问题内容: 我的程序使用该类(系统偏好设置,而不是用户)将加密的产品密钥数据保存到计算机。问题是,在Windows和Linux上(尚未在OSX上进行测试,但可能是相同的),如果我不使用具有管理员权限的程序运行该程序,则在尝试读取或读取该程序时,它将发出异常或警告。保存数据。 显然,要求用户以“管理员”权限运行程序是不切实际的。理想情况下,我希望操作系统请求用户许可。 这很愚蠢,并且消除了的一半目的

  • 问题内容: 当我使用getFromLocationName调用时,我得到一个IOException,描述为“ grpc failed”。 运行的代码 错误的控制台输出: Android SDK版本(API级别):25 Android Studio插件是最新的。 提前致谢! 编辑: 问题现在似乎已经解决,这是我的解决方案。 问题答案: 更新: 该问题现在似乎已解决。我不确定问题是否就此解决了,因此,

  • 我写了一个方便的屏幕键盘模块,当我在电脑上编写打算以平板模式运行的程序时,我可以导入和使用它。因为我想在未来的许多程序中导入和使用这个实用程序,我想存储当前鼠标位置和在模块开始时鼠标可见性状态,然后在模块退出时恢复那些条件。mouse.get_pos()命令工作正常,但是.mouse.get_visible()命令失败,返回错误消息:AtiniteError:模块'pygame.mouse'没有属

  • 我正在尝试构建我的Android应用程序与Gradle在控制台。但关于任务“:app:TransformClasseSandResourcesWithProGuardForRelease”的获取以下错误: ./gradlew构建--堆栈跟踪 这是我收到的例外情况:

  • “:App:TransformClassesWithDexForDebug”。>com.android.build.transform.api.transformException:当我在studio项目中添加Facebook最新SDK时 Android Studio TransformException:错误:任务“:app:TransformClassesWithDexForDebug”执行失