EACCES(权限被拒绝)Android



GOAL:使用intent对通过外部源(例如sd卡、内部或驱动器(检索的image/content执行压缩。

我能够获得检索到的内容的实际路径,但当我试图使用压缩库(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"

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

最新更新