Giter Site home page Giter Site logo

Comments (3)

ocram avatar ocram commented on May 21, 2024

Thanks for your question!

You understood everything correctly and put this method in the right place. The only problem you have is the missing filename, right?

Well, that's easier than you might have thought:

Actually, you could just hard-code a filename into that method, which would look like this:

final String filename = "my-file.txt;

But this would always download and save any file under the name my-file.txt. That's probably not what you want, right?

But you can do everything you want with this filename. For example, you could add the current timestamp at the beginning of that name so that files have unique names:

final String filename = System.currentTimeMillis()+" my-file.txt";

Alternatively, you could include your app's name, etc.

But another important thing that you'd probably want to change is the file extension. If you know what extension the file must have, that's great, then you can hard-code it as in the examples above. But often, it won't always be a text file, so you could detect the file extension from the MIME type that is passed as a method parameter:

final String filename;
if (mimetype.equals("image/jpeg")) {
    filename = "my-photo.jpg";
}
else if (mimetype.equals("text/html")) {
    filename = "my-document.html";
}
else {
    // we didn't expect this MIME type and so we don't have any reasonable extension
    filename = "my-file";
}

Hope that helps!

from android-advancedwebview.

Shirishasai avatar Shirishasai commented on May 21, 2024

Thanks for your suggestion it worked .:-)
But am unable to cancel the download once started .Can you please help on it.

from android-advancedwebview.

ocram avatar ocram commented on May 21, 2024

Glad that it worked :)

Cancelling any download is not currently possible when you let this library handle the downloads automatically. This would be possible in the future, but it will require some small changes to the source code:

Here and here, DownloadManager#enqueue() is called, which returns a unique ID for each download. Those IDs would have to be stored and be passed to DownloadManager#remove() when a future method (potentially named stopDownloads() or something like this) would be called.

Is this really important? From what we know, cancelling downloads is only rarely needed.

from android-advancedwebview.

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.