【问题标题】:adding lines to your AndroidManifest.xml file - fail to provide permission在您的 AndroidManifest.xml 文件中添加行 - 无法提供权限
【发布时间】:2021-04-08 23:09:51
【问题描述】:

我已经设置了允许外部存储文档并可能列出所有 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
  }

【问题讨论】:

  • 您是否使用flutter clean 清理了项目?如果没有,请清理它并重新运行您的应用

标签: android firebase flutter dart permissions


【解决方案1】:

添加以下权限后:

<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.
}

【讨论】:

  • 谢谢,请求存储权限放在哪里?
  • 在调用方法访问文件之前
猜你喜欢
  • 2013-06-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多