android - 在您的 AndroidManifest.xml 文件中添加行 - 无法提供权限
问题描述
我已经授予允许外部存储文档并可能列出所有 PDF 文档的权限。尽管将这些行添加到您的 AndroidManifest.xml 文件中,但在启动小部件时仍会出现错误消息。
请告知如何修复此错误消息。
Exception has occurred.
FileManagerError (
Try to add thes lines to your AndroidManifest.xml file
`<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>`
`<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>`
and grant storage permissions to your applicaion from app settings
FileSystemException: Directory listing failed, path = '/storage/emulated/0/' (OS Error: Permission denied, errno = 13))
这是错误来自的方法:
void getFiles() async { //asyn function to get list of files
List<StorageInfo> storageInfo = await PathProviderEx.getStorageInfo();
var root = storageInfo[0].rootDir; //storageInfo[1] for SD card, geting the root directory
var fm = FileManager(root: Directory(root)); //
files = await fm.filesTree(
excludedPaths: ["/storage/emulated/0/Android"],
extensions: ["pdf"] //optional, to filter files, list only pdf files
);
setState(() {}); //update the UI
}
解决方案
添加以下权限后:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
将以下包添加到pubspec.yaml
文件中:
https://github.com/Baseflow/flutter-permission-handler
dependencies:
permission_handler: ^5.0.1+1
然后你可以请求存储权限:
if (await Permission.storage.request().isGranted) {
// Either the permission was already granted before or the user just granted it.
}
推荐阅读
- python-3.x - Dataflow into Beam Pipeline 中的附加参数
- ios - 如果我使用 SnapshotListener,如何在 TableView 中为删除行和部分设置动画?
- javascript - 如何将此 jQuery 代码转换为纯 Javascript(HTML Affix)?
- python - 为什么“try ... except KeyError ...”比“dict.get”慢?
- html - 片段中的 Bean 预处理器未正确处理我的表单对象
- batch-file - 将两个或多个唯一变量回显到文本文件
- angular - Angular 中的一些动画不应该出现
- c++ - 如何提供对大型数组元素的线程安全访问
- arrays - 为什么这个函数显示一个数组而不是一个数组?
- omnet++ - 我不知道为什么这些错误会发生在 omnet++ 静脉中