Android Question Webview path

Alessandra Pellegri

Active Member
Licensed User
Longtime User
I have my html files stored in a sqllite database.
When I have to show them in webview I take them from database and I use LoadHTML method of webview.

The issue is: how can I redirect webview so it can read local links (for example href="logo.gif") from a specified folder ?


Thank you
 

warwound

Expert
Licensed User
Longtime User
Alternatively you could use WebViewExtras2 library.
You'd set a WebViewClient and listen for the WebViewClient's event:

ShouldInterceptRequest(Url As String) As WebResourceResponse

That event is raised whenever the WebView requests a resource - a resource being an image such as your logo.gif.
In the event you can return either:
  • A WebResourceResponse which has been initialized with an InputStream that contains the data for the requested resource.
    The WebView will load the requested resource from the WebResourceResponse.
  • Null.
    The WebView will try to load the requested response using HTTP - it'll request the resource from the resource's URL.

There's a code example in this post:
https://www.b4x.com/android/forum/t...with-a-webresourceresponse.42476/#post-257175

This technique will only be of use if you can initalize a WebResourceResponse with an InputStream that contains the data required for the requested resource.
Can you get your logo.gif binary data from your database, convert it to a byte array and then initialize an InputStream using it's InitializeFromBytesArray method?
If so then this technique may work for you.

WebViewExtras2 can be found here:
http://b4a.martinpearman.co.uk/webviewextras/.
 
Upvote 0
Top