Android Question how to create browser

William Lancee

Well-Known Member
Licensed User
Longtime User
https://www.b4x.com/android/forum/posts/230988/


B4X:
Sub Globals
 Dim WebV As WebView
End Sub

Sub Activity_Create(FirstTime AsBoolean)
 Activity.LoadLayout("Layout1")
 WebV.Initialize("WebV")
 Activity.AddView(WebV, 0dip, 0dip, 100%x, 100%y)
 WebV.LoadHtml("<html><body background='" & WebViewAssetFile("image.jpg") & "'></body></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
 
Last edited:
Upvote 0

emexes

Expert
Licensed User
how to create browser?
This is probably not quite what you're looking for, but... while I'm in a extra-spanner-in-the-toolbox frame-of-mind*:

https://www.b4x.com/android/forum/threads/open-the-browser-with-a-specific-web-page.6666/#content

which is slightly outdated, but now possibly as simple as:
B4X:
Private Browser As Intent
Browser.Initialize(Browser.ACTION_VIEW, "http://www.theage.com.au")
StartActivity(Browser)
It does lessen your grip on your user, but to that I would say:

1/ we love our users
2/ if you love someone, set them free...

Or if that doesn't sway you, let's give Isaac Newton a shot:

If I have seen further it is by standing on ye sholders of Giants.

:)


* or possibly an Australian shortcut she'll be right mate frame-of-mind
 
Last edited:
Upvote 0
Top