【问题标题】:EACCES (Permission denied) AndroidEACCES(权限被拒绝)Android
【发布时间】:2020-06-03 04:09:52
【问题描述】:

目标:对image/content 执行压缩,使用意图通过外部来源(例如:sd 卡、内部或驱动器)检索。

我能够获取检索到的内容的实际路径,但是当我尝试使用压缩库 (zetbaitsu/Compressor) 对其进行压缩时,它的抛出错误

打开失败:EACCES(权限被拒绝)。

我已经交叉检查了我的权限并尝试了多种方法来确认权限访问,仍然是它的抛出错误。

这是我的功能:

void handleSendImage(Intent intent) {
    try {
        Uri imageUri =  intent.getParcelableExtra(Intent.EXTRA_STREAM);
        Log.d(TAG, "handleSendImage: " + imageUri.toString());
        File imageFile = new File(getFilePath(this, imageUri));
        Log.d(TAG, "handleSendImage: " + Uri.fromFile(imageFile));
        File compressedFile = new Compressor(this).compressToFile(imageFile);

    } catch (Exception e) {
        Log.e(TAG, "handleSendImage: " + e.getMessage());
    }
}

这是我的日志输出:

handleSendImage: content://com.android.providers.media.documents/document/image%3A30

handleSendImage: file:///storage/emulated/0/Download/4c568534307d605ed94878dc06d933ee.jpg

handleSendImage: /storage/emulated/0/Download/4c568534307d605ed94878dc06d933ee.jpg: open failed: EACCES (Permission denied)

【问题讨论】:

  • android:requestLegacyExternalStorage="true" 在清单应用标签中添加此权限

标签: android compression image-compression file-access


【解决方案1】:

android:requestLegacyExternalStorage="true"

将此添加到 Manifest 文件中,但这在 android 11 中不起作用

【讨论】:

  • 您知道在针对 Android 11 时如何解决此问题吗?我在 Android 11 中遇到了这个问题,我想问 MANAGE_EXTERNAL_STORAGE 用户是否遇到异常,但它需要一些工作,而且通过谷歌审查@bhaskar-pasupula
猜你喜欢
  • 1970-01-01
  • 2015-08-28
  • 2020-02-14
  • 2014-05-11
  • 1970-01-01
  • 1970-01-01
  • 2011-12-28
  • 2015-07-20
  • 2016-03-14
相关资源
最近更新 更多