Giter Site home page Giter Site logo

Comments (11)

dJani97 avatar dJani97 commented on August 11, 2024 1

Thanks, I followed this solution and now opening files works well: #85

from background_downloader.

396501293 avatar 396501293 commented on August 11, 2024
                final task = DownloadTask(
                    url: downloadStartRequest.url.toString(),
                    filename: downloadStartRequest
                            .url.queryParameters['fullFileName'] ??
                        '้™„ไปถ'); // define your task

                pd ??= ProgressDialog(context: context);

                pd!.show(
                  max: 100,
                  msg: localizations.downloadStatusRunning,
                  progressType: ProgressType.valuable,
                  progressBgColor: Colors.transparent,
                  hideValue: true,
                  closeWithDelay: 1000,
                  cancel: Cancel(
                    cancelClicked: () {
                      FileDownloader().cancelTaskWithId(task.taskId);
                    },
                  ),
                  completed: Completed(
                      completedMsg: localizations.downloadStatusComplete),
                  // onStatusChanged:
                );

                TaskStatusUpdate result = await FileDownloader().download(
                  task,
                );

                if (result.status == TaskStatus.complete) {
                  pd!.update(
                    value: 100,
                  );
                  FileDownloader().openFile(task: task);
                }

I alter the code to this. Still not work on android. It stuck in FileDownloader.dowload() without response.
The console logs "Enqueuing task with id xxxx"

from background_downloader.

781flyingdutchman avatar 781flyingdutchman commented on August 11, 2024

Hi, thanks for trying the package. A few thoughts:

  1. You need to do something with the result of the call to download, for example to capture failures/errors - you shouldn't just ignore the return value
  2. You need to make sure your url and urlQueryParameters are url encoded - it's not clear from the example that you do that and it will fail if you don't

from background_downloader.

396501293 avatar 396501293 commented on August 11, 2024
 bool result = await FileDownloader().enqueue(task);

    if (result) {
      pd!.update(
        value: 100,
      );
      FileDownloader().openFile(task: task);
    }

I just modify "download" to "enqueue" and successfully downloaded. But another error show:

Failed to open file /data/user/0/com.example.prime_layer_flutter/app_flutter/image3303709270623290067.jpg: java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/com.example.prime_layer_flutter/app_flutter/image3303709270623290067.jpg

Did I miss any configurations?

from background_downloader.

781flyingdutchman avatar 781flyingdutchman commented on August 11, 2024

For some reason (that I don't understand) on Android you can't open a file that is downloaded in the documents directory (the default for a Task). Download to a different directory (e.g. temporary) and it should work.

from background_downloader.

781flyingdutchman avatar 781flyingdutchman commented on August 11, 2024

Looking at your code again, it seems like you try to open them file right after the call to enqueue. Enqueue does just that: puts the request in the queue. It doesn't compete the request. You need to listen to updates or register a handler.
Please read the documentation.

from background_downloader.

396501293 avatar 396501293 commented on August 11, 2024
 @override
  void initState() {
    super.initState();
    FileDownloader().registerCallbacks(
      taskStatusCallback: myDownloadStatusCallback,
    );
  }

  void myDownloadStatusCallback(TaskStatusUpdate update) {
    if (update.status == TaskStatus.complete) {
      pd!.update(
        value: 100,
      );

      FileDownloader().openFile(task: update.task);
    }
}

I register a task status callback handler. But only the first state(enqueued) update was processed. The next state update did not occur.

from background_downloader.

396501293 avatar 396501293 commented on August 11, 2024

I run the example. Same problem.

image

from background_downloader.

781flyingdutchman avatar 781flyingdutchman commented on August 11, 2024

If the example doesn't move past enqueued then that means the task does not complete, not even with an error (which would show in the example app).

Have you modified the example app to load a different file, or does the example app download the original file from the repo? If the original, there has to be an issue with how your device reaches the network (that app has always worked, so if it doesn't complete it means there is an issue with the network). If you've modified the example to load 'your' file then I think there is an issue with how you have defined your task, eg urlencoding etc.

Perhaps if you can provide:

  1. The version of the downloader you are using
  2. The version of Android
  3. Logs from the device (including those labeled TaskWorker and BackgroundDownloaderPlugin, as those are on the Kotlin side)

from background_downloader.

dJani97 avatar dJani97 commented on August 11, 2024

I also get the same error when I tap on a notification to open the file, or when I call .openFile(task: result.task):
java.lang.IllegalArgumentException: Failed to find configured root that contains ...

See my logs, the file does get downloaded:

I/BackgroundDownloader(25786): Enqueuing task with id 1152481977
I/flutter (25786): PXL_20230207_101333993.jpg status: TaskStatus.enqueued
I/TaskWorker(25786): Starting task with taskId 1152481977
I/flutter (25786): PXL_20230207_101333993.jpg status: TaskStatus.running
I/flutter (25786): PXL_20230207_101333993.jpg progress: 0.0%
I/TaskWorker(25786): Successfully downloaded taskId 1152481977 to /data/user/0/com.myapp.staging/app_flutter/PXL_20230207_101333993.jpg
I/flutter (25786): PXL_20230207_101333993.jpg progress: 100.0%
I/flutter (25786): PXL_20230207_101333993.jpg status: TaskStatus.complete
I/flutter (25786): Success!
I/WM-WorkerWrapper(25786): Worker result SUCCESS for Work [ id=bcdad762-6b32-4894-a235-9b0371f59dbd, tags={ com.bbflight.background_downloader.TaskWorker, BackgroundDownloader, taskId=1152481977, group=await } ]

Flutter 3.10.6
background_downloader: 7.9.4
Tested on both Android 11 & 13

from background_downloader.

781flyingdutchman avatar 781flyingdutchman commented on August 11, 2024

Hi, per comment above, I think you're running into this:

For some reason (that I don't understand) on Android you can't open a file that is downloaded in the documents directory (the default for a Task). Download to a different directory (e.g. temporary) and it should work.

from background_downloader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.