- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 downloads_path_provider
要写入下载目录的包。我按照推荐的方式设置了它 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
到项目AndroidManifest.xml
但是当我尝试写的时候我得到了这个错误 E/flutter (26091): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: FileSystemException: Cannot open file, path = '/storage/emulated/0/Download/secure-strorage-backup.txt' (OS Error: Permission denied, errno = 13)
这是代码
final file = _localFile;
file.writeAsString('1234 5678\n');
file.writeAsString('1234 5678\n');
File get _localFile {
final path = _downloadsDirectory.path;
return File('$path/secure-strorage-backup.txt');
}
如何写入下载文件夹?
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.user.myappname">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:name="io.flutter.app.FlutterApplication"
android:label="Secure Storage"
...
这是我获取下载目录的方式
void initState() {
super.initState();
initDownloadsDirectoryState();
}
Future<void> initDownloadsDirectoryState() async {
Directory downloadsDirectory;
try {
downloadsDirectory = await DownloadsPathProvider.downloadsDirectory;
} on PlatformException {
print('Could not get the downloads directory');
}
if (!mounted) return;
setState(() {
_downloadsDirectory = downloadsDirectory;
});
}
最佳答案
如 this 中所述回答,你还需要明确询问你的用户是否允许使用外部存储,你可以使用this那个包
更新:
this包变得更好并且有更好的分数,你可以这样使用它:
await Permission.storage.request();
Directory downloadsDirectory = await DownloadsPathProvider.downloadsDirectory;
final String path = downloadsDirectory.path;
final File file = File('$path/secure-strorage-backup.txt');
await file.writeAsString('1234 5678\n');
await file.writeAsString('1234 5678\n');
print(await file.readAsString());
关于flutter - downloads_path_provider — 操作系统错误 : Permission denied, errno = 13,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61559351/
我正在使用 This package在android中获取下载路径,效果很好。通过使用这个包,我得到了我想要的 /storage/emulated/0/Download。 问题:当我运行 flutte
我正在使用 flutter 开发移动应用程序。为此,我使用了 downloads-path-provider获取手机的下载目录。模拟器返回 /storage/emulated/0/Download .
我使用 downloads_path_provider要写入下载目录的包。我按照推荐的方式设置了它 到项目AndroidManifest.xml 但是当我尝试写的时候我得到了这个错误 E/flutte
我使用 downloads_path_provider要写入下载目录的包。我按照推荐的方式设置了它 到项目AndroidManifest.xml 但是当我尝试写的时候我得到了这个错误 E/flutte
我是一名优秀的程序员,十分优秀!