Android Question Images loaded in webviews are not displayed in mode “debug (rapid)” B4A 3.50 version

bgsoft

Well-Known Member
Licensed User
Longtime User
In the new Basic4Android 3.50 version, I realised that images loaded in webviews are not displayed in mode “debug (rapid)”. In other modes, as “debug (legacy)” and “release” are shown normally.


There is a simple example to check this:

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='file:///android_asset/image.jpg'></body></html>")

End Sub

regards
 

Attachments

  • exampleImgWebview.zip
    493.2 KB · Views: 1,595

Erel

B4X founder
Staff member
Licensed User
Longtime User
By default the rapid debugger saves the assets files in a "virtual assests folder". This allows the debugger to only update modified files instead of packaging all the files each deployment.

You have two options:
1. Disable the virtual assets folder feature. Add this line to the main activity: #DebuggerForceStandardAssets: true

Or better:
2. Use this code (requires JavaObject library):
B4X:
WebV.LoadHtml("<html><body background='" & WebViewAssetFile("image.jpg") & "'></body></html>")


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

This sub will load the correct file in all modes.
 
Upvote 0

bgsoft

Well-Known Member
Licensed User
Longtime User
Thank you very much Erel
 
Upvote 0

ibra939

Active Member
Licensed User
Longtime User
Thanks
 
Upvote 0

PSEAD

Member
Licensed User
Longtime User
I had a slightly different problem which was fixed by adding "#DebuggerForceStandardAssets: true"
When loading a BMP as a panel background image using the designer, it did not show when using the Rapid Debugger but did show using the Legacy Debugger.
The image did show correctly when I changed it to a PNG (without adding the "#DebuggerForceStandardAssets: true" line).
 
Upvote 0

leongcc

Member
Licensed User
Longtime User
I added #DebuggerForceStandardAssets: true, but there is an error when loading the layout at this statement, Activity.LoadLayout("mainmt").
I have tried adding different directory path but mainmt.bal still cannot be found by the compiler.

Using B4A 5.80.


B4X:
Error occurred on line: 372 (Main)
java.io.FileNotFoundException: mainmt.bal
    at android.content.res.AssetManager.openAsset(Native Method)
    at android.content.res.AssetManager.open(AssetManager.java:324)
    at android.content.res.AssetManager.open(AssetManager.java:298)
    at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:202)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:78)
    at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:208)
    at com.packagename.main._activity_create(main.java:603)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:702)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at com.packagename.main.afterFirstLayout(main.java:102)
    at com.packagename.main.access$000(main.java:17)
    at com.packagename.main$WaitForLayout.run(main.java:80)
    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:153)
    at android.app.ActivityThread.main(ActivityThread.java:5356)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
    at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Resume **
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
By default the rapid debugger saves the assets files in a "virtual assests folder". This allows the debugger to only update modified files instead of packaging all the files each deployment.

You have two options:
1. Disable the virtual assets folder feature. Add this line to the main activity: #DebuggerForceStandardAssets: true

Hi Erel,

I had a problem with fonticon's missing from this material drawer lib:

https://www.b4x.com/android/forum/threads/msmaterialdrawer.53883/

And this flag (#DebuggerForceStandardAssets: true) fixed that issue.

But, obviously the more asset files my project has, the less "rapid" the debugger will be.

How can I "refresh" the contacts of this "virtual assets folder" so it has all my physical asset files in it, so I won't need to slow down the debugger using this flag?
 
Upvote 0
Top