将行添加到您的 AndroidManifest.xml 文件 - 无法提供权限
adding lines to your AndroidManifest.xml file - fail to provide permission
我已经设置了允许文档外部存储的权限,并可能列出所有 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.
}
我已经设置了允许文档外部存储的权限,并可能列出所有 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.
}