Issue
I am loading a html file into a WebView and want to override the WebView's requests to stylesheet <link>
and <image>
elements in the <head>
so that I can load a file from the machine
the links in the html are like so
<head>
<link href="../stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<svg width="100%" height="100%" viewBox="0 0 352 500>
<image width="352" height="500" xlink:href="image.jpeg"/>
</svg>
</body>
I have a WebViewClient with this code but none of these make a request to these links. shouldInterceptRequest and onLoadResource both just recieve the entire html file at request?.url
class EpubWebViewClient(): WebViewClient() {
override fun onLoadResource(view: WebView?, url: String?) {
Log.i("loadurl", "onLoadResource $url")
super.onLoadResource(view, url)
}
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
Log.i("loadurl", "shouldOverrideUrlLoading ${request?.url}")
return super.shouldOverrideUrlLoading(view, request)
}
override fun shouldInterceptRequest(
view: WebView?,
request: WebResourceRequest?
): WebResourceResponse? {
Log.i("loadurl", "shouldInterceptRequest ${request?.url}")
return super.shouldInterceptRequest(view, request)
}
}
I would image there is a function like but perhaps there is not idk
override fun idealUrlOverloadFunction(url: String): String or something else {
return openLocalFile(url)
}
Does the WebView or WebViewClient even make requests for these?
If so how can I interupt them and load a resource from the machine instead of the web?
Solution
solved by me, consider this link
<link href="../stylesheet.css" rel="stylesheet" type="text/css"/>
apending some `string + :' combo such as
<link href="mystuff:../stylesheet.css" rel="stylesheet" type="text/css"/>
will cause it to show up in shouldInterceptRequest()
I am unsure as to weather this is caused by the link not firing or shouldInterceptRequest not listening though, but an easy fix with .replace
Answered By - Noah
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.