【问题标题】:Alternative of MANAGE_EXTERNAL_STORAGEMANAGE_EXTERNAL_STORAGE 的替代方案
【发布时间】:2023-01-21 20:16:53
【问题描述】:

我正在尝试删除 MANAGE_EXTERNAL_STORAGE,但在删除此权限后我无法从给定路径上传 Multipart。

我正在使用这行代码来获取 pdf 文件,

`Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("application/pdf");
resultLauncher.launch(intent);`

我得到了这样的路径 /storage/emulated/0/Download/offer.pdf

获得此路径后,我使用以下代码将其转换为 Multipart 并将其上传到服务器,

`File file = new File(path);
MultipartBody.Part filePart = MultipartBody.Part.createFormData("file", file.getName(), RequestBody.create(file,      MediaType.parse("application/pdf")));`

在将其上传到服务器时出现错误:

java.io.FileNotFoundException: /storage/emulated/0/Documents/mSchooling/offer.pdf: open failed: EACCES (Permission denied).

一件事是我已经给出了 read_external_storage 和 write_external_storage。

请帮我解决这个问题。

我试过这段代码来获取文件,

ntent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("application/pdf"); resultLauncher.launch(intent);

并尝试使用以下代码将其转换为 Multipart,

File file = new File(path); MultipartBody.Part filePart = MultipartBody.Part.createFormData("file", file.getName(), RequestBody.create(file, MediaType.parse("application/pdf")));

【问题讨论】:

    标签: java android


    【解决方案1】:

    我得到了 /storage/emulated/0/Download/offer.pdf 这样的路径

    不,你不是。

    你会得到一个带有 ACTION_GET_CONTENT 的漂亮的 uri。内容方案。

    使用那个 uri。

    谷歌输入流请求体。

    【讨论】:

      猜你喜欢
      • 2021-02-13
      • 1970-01-01
      • 2015-06-13
      • 2015-03-03
      • 2015-09-25
      • 2019-12-16
      • 2011-06-20
      • 2015-11-03
      • 2014-04-03
      相关资源
      最近更新 更多