Android Question Webview path

Discussion in 'Android Questions' started by Alessandra Pellegri, Jul 28, 2015.

  1. Alessandra Pellegri

    Alessandra Pellegri Active Member Licensed 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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    You will need to create a temporary folder and copy all the required files to that folder.
     
  3. Alessandra Pellegri

    Alessandra Pellegri Active Member Licensed User

  4. warwound

    warwound Expert Licensed 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:
    http://www.b4x.com/android/forum/th...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/.
     
  5. Alessandra Pellegri

    Alessandra Pellegri Active Member Licensed User

    Thank you warwound.
    I am going to study this solution.
     
Loading...