I'm writing this because I could not find a quick answer to this question:
How do I load a set of web pages in a Webview that are contained in the Assets Directory?
This is how you load a page:
If you try this in DEBUG mode however, it will not work directly.
You also have to add this to the Project Attributes Region
NB You might think that you should use this construct
Unfortunately File.DirAssets does not point to the folder that is required namely android_asset
If your HTML files refer to other files in the Assets folder, they will not be found if you refer to them like this:
To get get the right reference use this:
(in fact in this case you could could put both links in your code, only one of them will get found. If you open the base file in an HTML viewer, it will get the CSS file from the first link)
I hope this saves someone else some time.
How do I load a set of web pages in a Webview that are contained in the Assets Directory?
This is how you load a page:
B4X:
WebView1.LoadUrl("file:///android_asset/form.html")
If you try this in DEBUG mode however, it will not work directly.
You also have to add this to the Project Attributes Region
B4X:
#DebuggerForceStandardAssets : true
NB You might think that you should use this construct
B4X:
Dim url="file:///" & File.Combine(File.DirAssets, "form.html")
Log("Loading " & url)
WebView1.LoadUrl(url)
Unfortunately File.DirAssets does not point to the folder that is required namely android_asset
If your HTML files refer to other files in the Assets folder, they will not be found if you refer to them like this:
B4X:
<link rel="stylesheet" type="text/css"
href="view.css" media="all" />
To get get the right reference use this:
B4X:
<link rel="stylesheet" type="text/css"
href="android_asset/view.css" media="all" />
(in fact in this case you could could put both links in your code, only one of them will get found. If you open the base file in an HTML viewer, it will get the CSS file from the first link)
I hope this saves someone else some time.