Hello friends, i have an old b4a app witch read html file from File.DirAssets with tihs code and display it on WebView:
B4X:
Activity.LoadLayout("home")
html = File.ReadString(File.DirAssets , "about.html")
WebView1.Initialize("WebView1")
Activity.AddView(WebView1, 0, 0, 100%x, 100%y)
WebView1.JavaScriptEnabled = True
WebView1.ZoomEnabled=False
' html = html.Replace("__BOOK_TITLE__",appBookName)
' html = html.Replace("__BOOK_DESCRIPTION__",appBookDescription)
WebView1.LoadHtml(html)
Into about.html i have this code:
HTML:
<html lang="en">
<head>
<meta charset="utf-8">
<title>title</title>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body background='file:///android_asset/images/image2.jpg'>
<!-- page content -->
some text here
<img src="file:///android_asset/images/image.jpg" alt="Smiley face" height="542" width="542">
another text here
</body>
</html>
BUT! Yesterday i install clear copy of Windows 10 64 bit. Then I install everithing for B4A acording https://www.b4x.com/b4a.html.
Since then i cant display images from about.html. file:///android_asset/ is not work....
On my other pc with B4A ver. 10 everithing works perfect
I check - the problem is not in Jdk 11. Everithin else is the same. Can anybody give me a clue?
I attach a little project witch not work on b4a ver. 11
The problem is in mapping the DirAsset folder. I suggest you copy files and folders from DirAsset to the shared folder using the file provider and then modify the HTML file and enter a new destination for the files and folders. I repeat, the problem is in mapping DirAsset for SDK30 and B4A11.
Second, you are using an older version of the WebViewExtra library. I'll give you a suggestion, download the library and B4A example from the link below. In B4AExample Activity_Create, copy all folders and files from DirAsset to the Shared folder. Before that, change the paths to the files in the HTML file to the paths for the shared folder. When you do all this, use the LoadFileFromDirAsset method to open the HTML file, do not use LoadHTML or...
Your project seems to work fine with B4A 11.20 on a Pixel 4a with Android 12 and a Redmin Note 9 Pro with Android 11. Both with targetSdkVersion of 26 as you posted and also when set to 30 as required by the Play Store. However your are not loading the html from a sub-folder as indicated in your title so I don't know what you are asking about.
OK! Yes... my mistake... The html file is into Files directory in my project....Into FIles dir there are directories like images with two pictures....., CSS, js
But when i start project this pictores are not visible.... Css is not loaded...that is only when i installed B4A 11 on b4A 10 everithing work perfect...
May be i miss something... But i thing that not neded to load all dirs and files into Files manager as shown....
If you use on device with SDK30 (android 11), WebSetting.setAllowFileAccess i set to false by default. Try to set it to TRUE. On lower SDK's is set to true by default.
The problem is in mapping the DirAsset folder. I suggest you copy files and folders from DirAsset to the shared folder using the file provider and then modify the HTML file and enter a new destination for the files and folders. I repeat, the problem is in mapping DirAsset for SDK30 and B4A11.
Second, you are using an older version of the WebViewExtra library. I'll give you a suggestion, download the library and B4A example from the link below. In B4AExample Activity_Create, copy all folders and files from DirAsset to the Shared folder. Before that, change the paths to the files in the HTML file to the paths for the shared folder. When you do all this, use the LoadFileFromDirAsset method to open the HTML file, do not use LoadHTML or LoadHTMLString.
I have been struggling for a long time in my projects with a similar problem that you have and I solved it in this way.
IMPORTANT!!! Library deprecated. Use UltimateWebView2 instead. https://www.b4x.com/android/forum/threads/ultimatewebview2.158340/ The purpose of the library is to implement all important classes in one library in order to make work as easy as possible. The library will be upgraded over time by...
Here is the solution for your project. Download the project and the UltimateWebView library below. Pay attention to the settings of the UltimateWebView object in the Designer (CustomView Properties).
Here is the solution for your project. Download the project and the UltimateWebView library below. Pay attention to the settings of the UltimateWebView object in the Designer (CustomView Properties).