Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callback for download complete not available #5

Open
fabrz opened this issue Apr 13, 2018 · 5 comments
Open

Callback for download complete not available #5

fabrz opened this issue Apr 13, 2018 · 5 comments

Comments

@fabrz
Copy link

fabrz commented Apr 13, 2018

Hi,

Is there a way to open the downloaded file as soon as it's been downloaded? I'm trying to rely on the success callback but it looks like that method gets fired before the download it's complete.

Hence why I can't find the file in the Download folder of the device yet. I'll share some code with you so you can get a better understanding of it.

  updateAndroidApp(url) {
    const fileName = url.substring(url.lastIndexOf('/') + 1);

    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, (fileSystem) => { // eslint-disable-line
      const onDownloadFailure = (message) => { // eslint-disable-line
        // @todo: handle the error message
      };

      const onDownloadSuccess = (data) => { // eslint-disable-line
        const fileURL = `${window.cordova.file.externalDataDirectory}Download/${fileName}`;
        fileOpener.open(fileURL);
      };

      window.cordova.plugins.DownloadManager.download(url, onDownloadSuccess, onDownloadFailure);
    });
  }

Cheers

@vasani-arpit
Copy link
Owner

The success is in the sense of successfully started downloading that means Plugin has successfully tell OS to start downloading this particular file.

The feature you are asking for is yet to be added to the plugin.

@ramoncarreras
Copy link

This is implemented in the PULL REQUEST #2

Unfortunately, it has never been merged.

@vasani-arpit
Copy link
Owner

Yes. I am occupied with other projects. I'll make time for this one.

@ramoncarreras
Copy link

OK @vasani-arpit. Thanks.

@asoap
Copy link

asoap commented Oct 16, 2018

If I'm reading this correctly, the PR is for something else. addCompletedDownload let's you just tell the DownloadManager to add a file. I'm currently using it, but it's getting all screwed up for me, as any file I add isn't able to be opened.

https://developer.android.com/reference/android/app/DownloadManager.html#addCompletedDownload(java.lang.String,%20java.lang.String,%20boolean,%20java.lang.String,%20java.lang.String,%20long,%20boolean)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants