EACCES(权限被拒绝)Android

时间:2020-02-19 03:50:34

标签: android compression image-compression file-access

目标:要对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)

1 个答案:

答案 0 :(得分:2)

android:requestLegacyExternalStorage="true"

将其添加到清单文件中,但在android 11中将无法使用