Unable to open downloaded file in Android for flutter_downloader
Asked Answered
B

1

7

I am trying to download a dummy .mp4 (or any file) through flutter_downloader. Here is my code snippet

void mobileDownload(filename) async {
    final status = await Permission.storage.request();
    if (status.isGranted){ //user grants download permission
        final storagePath = await getExternalStorageDirectory();
        print(storagePath!.path);
        final taskId = await FlutterDownloader.enqueue(
          url: 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerEscapes.mp4',
          savedDir: storagePath.path,
          fileName: '$filename.mp4',
          showNotification: true,
          openFileFromNotification: true,
        );
    }
  }

With the generic call back written (same as the one provided here https://pub.dev/packages/flutter_downloader) I am able to see my file being downloaded, with progress being shown as such

D/DownloadWorker( 6368): Update too frequently!!!!, this should be dropped
I/flutter ( 6368): 97
D/DownloadWorker( 6368): Update notification: {notificationId: 10, title: testApp.mp4, status: 2, progress: 100}
D/DownloadWorker( 6368): insert description= _display_name=testApp.mp4 datetaken=1625756663182 mime_type=video/mp4 _data=/storage/emulated/0/Android/data/com.example.flutter_app/files/testApp.mp4 title=testApp.mp4 date_added=1625756663182 to MediaStore
I/flutter ( 6368): 100
D/DownloadWorker( 6368): Update too frequently!!!!, but it is the final update, we should sleep a second to ensure the update call can be processed
I/flutter ( 6368): 100
D/DownloadWorker( 6368): Update notification: {notificationId: 10, title: testApp.mp4, status: 3, progress: 100}
D/DownloadWorker( 6368): File downloaded
I/WM-WorkerWrapper( 6368): Worker result SUCCESS for Work [ id=01c89c79-31e1-4375-a594-6ddcc27b9681, tags={ flutter_download_task, vn.hunghd.flutterdownloader.DownloadWorker } ]

I am also able to see that the download is complete through the notification center (https://i.sstatic.net/1VBno.jpg)

My issue is that I cannot access the downloaded files, no matter if they are .mp4, .mp4, .pdf or anything. Since I have openFileFromNotification set to true, I do not know why I am also unable to open the file from the notification bar. I can't seem to find them within the Files application either.

Any suggestions? I have the permissions set within the AndroidManifest.xml file as such:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />

Edit: Looking through flutter_downloader's issue page on Github, it appears it does not work for Android 11 which could be my problem.

Edit: Could not get it to work with Android 11. Decided to use Dio to download instead. If anyone can't get it to work either, this was a great tutorial: https://www.youtube.com/watch?v=3gNd1Ma-gss&list=FLcgfafWRwPYXKs6NliCs5Xw&index=1&t=85s. Along with that video, this tutorial https://medium.com/@michallot/how-to-write-a-simple-downloading-app-with-flutter-2f55ae516867 helped with displaying notifications.

Bony answered 8/7, 2021 at 15:18 Comment(3)
Did you find any solution ?Felsite
No I did not. Was a very frustrating experience. I ended up using DioBony
I think this is in android 9 or later. I use another plugin to open the file using the storage path.Disrelish
M
0

This is a known bug in flutter_downloader with no known workarounds at present. The openFileFromNotification should still work as expected on Android 10 and lower.

Manganite answered 8/8, 2022 at 16:34 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.