Android-AdvancedWebView icon indicating copy to clipboard operation
Android-AdvancedWebView copied to clipboard

feature add suggestion in handleDownload

Open belal-azzam opened this issue 8 years ago • 5 comments

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);

belal-azzam avatar Dec 04 '17 07:12 belal-azzam

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", "...");
	}

});

ocram avatar Dec 04 '17 13:12 ocram

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

belal-azzam avatar Dec 04 '17 16:12 belal-azzam

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

miyurusagarage avatar Jan 07 '18 07:01 miyurusagarage

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?

ocram avatar Jan 09 '18 19:01 ocram

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

adamvalt avatar Aug 24 '23 23:08 adamvalt