admin管理员组

文章数量:1357273

I have an app that displays web content using flutter_inappwebview. I need to download PDF files from the website, but I haven't been able to request permission and download the file successfully. Even when I manually grant the permission, the download process starts but fails.

Here is the code I used for checking permissions and downloading the file:

Future<void> _checkPermissions() async {
    if (Platform.isAndroid) {
      if (Platform.version.startsWith("13") || Platform.version.startsWith("14")) {
        await [
          Permission.photos,
          Permission.videos,
          Permission.audio,
        ].request();
      } else if (Platform.versionpareTo("30") >= 0) {
        await Permission.manageExternalStorage.request();
      } else {
        await Permission.storage.request();
      }
    } else if (Platform.isIOS) {
      await Permission.photos.request();
    }
  }

Future<void> _downloadFile(String url) async {
    try {
      Directory? directory;

      if (Platform.isAndroid) {
        directory = await getExternalStorageDirectory();
        String downloadsPath = "${directory!.path}/Download";
        directory = Directory(downloadsPath);

        if (!await directory.exists()) {
          await directory.create(recursive: true);
        }
      } else if (Platform.isIOS) {
        directory = await getApplicationDocumentsDirectory();
      }

      if (directory == null) {
        throw Exception("Klasör bulunamadı!");
      }

      print("

本文标签: androidHow can I download files on flutter webviewStack Overflow