flutter_downloader
flutter_downloader copied to clipboard
Download is Not Working
I'm getting this error
D/EGL_emulation( 2988): app_time_stats: avg=788.55ms min=4.57ms max=20855.36ms count=27
I/flutter ( 2988): Saved Directory: /storage/emulated/0/Android/data/com.example.pixifusion/files/downloads
I/flutter ( 2988): Download Task ID: f30f65e2-ab58-4e67-bd40-570efefad7e0
W/System.err( 2988): java.lang.NullPointerException
W/System.err( 2988): at vn.hunghd.flutterdownloader.DownloadWorker.downloadFile(DownloadWorker.kt:393)
W/System.err( 2988): at vn.hunghd.flutterdownloader.DownloadWorker.doWork(DownloadWorker.kt:206)
W/System.err( 2988): at androidx.work.Worker$1.run(Worker.java:86)
W/System.err( 2988): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
W/System.err( 2988): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
W/System.err( 2988): at java.lang.Thread.run(Thread.java:1012)
I/WM-WorkerWrapper( 2988): Worker result FAILURE for Work [ id=f30f65e2-ab58-4e67-bd40-570efefad7e0, tags={ flutter_download_task, vn.hunghd.flutterdownloader.DownloadWorker } ]
Same issue, it seems that in this code (DownloadWorker.kt)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && saveInPublicStorage) {
val uri = createFileInPublicDownloadsDir(actualFilename, contentType)
savedFilePath = getMediaStoreEntryPathApi29(uri!!)
outputStream = context.contentResolver.openOutputStream(uri, "w")
} else {
val file = createFileInAppSpecificDir(actualFilename!!, savedDir)
savedFilePath = file!!.path
outputStream = FileOutputStream(file, false)
}
uri or file var is null (depend on which Android version we have)
Did someone solved this issue? any fix?
You can add a try catch block here. I added it and my issue was resolved. In my case, a file with same name was already present on the location of my downloading file, and that's why it was failing. By adding a try catch, at least the code will not break.