delight-im / Android-AdvancedWebView

Enhanced WebView component for Android that works as intended out of the box
MIT License
2.39k stars 574 forks source link

feature add suggestion in handleDownload #166

Open belal-azzam opened 6 years ago

belal-azzam commented 6 years ago

some downloads need cookies because it's only accessible for logged users, i suggest you add a cookies parameter in the handleDownload function to be added to the request maybe something like this request.addRequestHeader("Cookie", cookies);

ocram commented 6 years ago

Good idea, thank you!

What about the following (more general) solution?

// DEFINITION OF THE CALLBACK:
public static interface DownloadManagerRequestConfigurator {

    public void configure(Request request);

}

// ...

// INTERNAL USAGE OF THE CALLBACK:
public static boolean handleDownload(final Context context, final String fromUrl, final String toFilename, final DownloadManagerRequestConfigurator configurator) {
    // ...
    if (configurator != null) {
        configurator(request);
    }
    // ...
}

// ...

// SUPPLYING THE CALLBACK WITH YOUR METHOD CALL:
AdvancedWebView.handleDownload(this, url, suggestedFilename, new DownloadManagerRequestConfigurator() {

    public void configure(final Request request) {
        request.addRequestHeader("Cookie", "...");
    }

});
belal-azzam commented 6 years ago

yeah that's even better keep up the good work!

miyurusagarage commented 6 years ago

Is this implemented now or planned for a near date? I also need this for the same scenario.

ocram commented 6 years ago

Yes, experimental support has been added in a separate branch here: https://github.com/delight-im/Android-AdvancedWebView/commit/7d23524a1838c681888d2c4068fa4d8fc97aafcb

If you would like to try this, please replace your Gradle dependency with

compile 'com.github.delight-im:Android-AdvancedWebView:7d23524a1838c681888d2c4068fa4d8fc97aafcb'

and add the following as the fourth parameter to the handleDownload method:

new AdvancedWebView.DownloadManagerRequestConfigurator() {

    public void configure(final DownloadManager.Request request) {
        // optionally configure the request instance here
    }

}

Does that work for you?

adamvalt commented 1 year ago

Yes, this works perfectly. Please merge it to the master branch.