Android Question WebView, HTML

kisoft

Well-Known Member
Licensed User
Hi
I try to open the html file (elem2.html) in webview.
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    WebView1.LoadHtml($"<img src="${WebViewAssetFile( "elem2.html")}"/>"$)
End Sub

Sub WebViewAssetFile (FileName As String) As String
  
    Dim jo As JavaObject
    jo.InitializeStatic("anywheresoftware.b4a.objects.streams.File")
    If jo.GetField("virtualAssetsFolder") = Null Then
        Return "file:///android_asset/" & FileName.ToLowerCase
    Else
        Return "file://" & File.Combine(jo.GetField("virtualAssetsFolder"), _
       jo.RunMethod("getUnpackedVirtualAssetFile", Array As Object(FileName)))
    End If
 
End Sub
I get a blank page. In which directory do I need to place the html file (elem2.html)?
Do I do it well at all?
 

johndb

Active Member
Licensed User
Hi
I try to open the html file (elem2.html) in webview.
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    WebView1.LoadHtml($"<img src="${WebViewAssetFile( "elem2.html")}"/>"$)
End Sub

Sub WebViewAssetFile (FileName As String) As String
 
    Dim jo As JavaObject
    jo.InitializeStatic("anywheresoftware.b4a.objects.streams.File")
    If jo.GetField("virtualAssetsFolder") = Null Then
        Return "file:///android_asset/" & FileName.ToLowerCase
    Else
        Return "file://" & File.Combine(jo.GetField("virtualAssetsFolder"), _
       jo.RunMethod("getUnpackedVirtualAssetFile", Array As Object(FileName)))
    End If
 
End Sub
I get a blank page. In which directory do I need to place the html file (elem2.html)?
Do I do it well at all?
Try this:
B4X:
WebView1.LoadUrl("file:///android_asset/" & "elem2.html")
 

kisoft

Well-Known Member
Licensed User
I don't understand how an html file can be a source of an img element...
I understand that this is a mistake
B4X:
 WebView1.LoadHtml($"<img src="${WebViewAssetFile( "elem2.html")}"/>"$)
How can I put this html file in the code?
 

Lucas Eduardo

Active Member
Licensed User
I checked in an example that I created with files from the cellphone, to use within webview, example (js, css) debugging is not loading but realizes that it works fine in realise mode
 

Erel

Administrator
Staff member
Licensed User
I checked in an example that I created with files from the cellphone, to use within webview, example (js, css) debugging is not loading but realizes that it works fine in realise mode
Use XUI.FileUri. It will work in all modes.

For the tests I took the content of the website.
B4X:
Dim xui As XUI
WebView1.LoadUrl(xui.FileUri(File.DirAssets, "elem2.html"))
 
Top