Fluttter android(操作系统错误:Permission denied,errno = 13)write to Downloads folder

kiayqfof  于 11个月前  发布在  Android
关注(0)|答案(1)|浏览(169)

我尝试将设备临时文件夹中的文件复制到Downloads文件夹,但在file.copy函数中出现此错误:

PathAccessException: Cannot copy file to '/storage/emulated/0/Download/test.pdf', path = '/data/user/0/myapp/cache/file-pdf.pdf' (OS Error: Permission denied, errno = 13)

字符串
代码如下:

await Permission.storage.request();
Directory downloadFolder = Directory("/storage/emulated/0/Download/")
String pdfName = "test";
await file.copy("${downloadFolder.path}$pdfName.pdf");


我正在使用permission_handler: ^11.1.0,我在AndroidManifest.xml上写了以下内容:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>


以下是我的build.gradle配置:

android {
    compileSdk flutter.compileSdkVersion
    ndkVersion flutter.ndkVersion

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion flutter.targetSdkVersion
    }
}


Flutter doctor输出:

[✓] Flutter (Channel beta, 3.18.0-0.2.pre, on macOS 14.2.1 23C71 darwin-arm64, locale pt-BR)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.3)
[✓] VS Code (version 1.85.1)
[✓] Connected device (2 available)
[✓] Network resources


我需要这个代码运行在Android 10到13.

eyh26e7m

eyh26e7m1#

当我将下面的标记添加到AndroidManifest.xml文件时,将文件保存在Downloads文件夹中工作(在Android 10到13上):

<application
    ...
    android:requestLegacyExternalStorage="true">

字符串
感谢@blackapps的帮助。

相关问题