html5 - Does android WebView support <a> tags with download attribute? is there any workarround? -
i'so have android app loads webview containing tags this
<a id="download-7630" href="/files/download/7630" download>somefilename.anyextension</a> in context of app's end files served java controller connecting mongodb. can't change server code need workaround this. requests return
responseentity.ok() .header("content-disposition", "attachment; filename=somefilename.anyextension") .contentlength(file.getlength()) .contenttype(mediatype.parsemediatype(file.getcontenttype())) .body(new inputstreamresource(file.getinputstream())); the problem i'm having download tags work on browser , console says example: "resource interpreted document transferred mime type application/pdf: "https://xyzdomain/files/download/22306"." when click them webview none of events fired up.
i have debug points in webviewclient's shouldoverrideurlloading(), onloadresource(), onpagestarted() , shouldinterceptrequest() , i nothing, somehow click or touch event being ignored tags formed this, else in app works fine in webview. (debug points work fine example when loading site contains links, or when navigating between pages in site)
my webview settings include:
websettings websettings = mwebview.getsettings(); websettings.setjavascriptenabled(true); websettings.setsaveformdata(true); websettings.setsavepassword(true); websettings.setdatabaseenabled(true); websettings.setdomstorageenabled(true); websettings.setsupportzoom(false); websettings.setallowfileaccess(true); websettings.setallowcontentaccess(true); mywebviewclient mywebviewclient = new mywebviewclient(); mwebview.setwebviewclient(mywebviewclient); mywebviewclient class extends webviewclient i'm overriding methods i'm trying debug
what i'm trying manage files server sends start intent offering user open file, problem haven't been able intercept try , that.
i've read solutions handle download in asynctaks or adding downloadlisteners , stuff problem haven't been able intercept click on links (html tags).
any ideas of might wrong or missing?
here's what's happening on browser:
- user clicks link (pointing file)
- browser gets http headers url / link, "it's attachment"
- browser / download manager handles smth downloaded rather redirected to
webview doesn't know how handle downloads, doesn't know how display content such content-type header , nothing.
what is:
- intercept redirect in webview (it should still happen, event if webview doesn't display when understands cannot)
- you'll url
- recognise 1 points file (for instance, regexp)
- handle file download outside webview
to intercept redirect url need to:
webview.setwebviewclient(new webviewclient() { @override public boolean shouldoverrideurlloading(webview view, string url) { // check url here - if file, // initiate download return false; } }
Comments
Post a Comment