Embeded file

kormos

Member
Licensed User
Longtime User
I have added a picture in my project and I have checked the checkbox on the left side of the file name. I try to display the image on a WebView. How can I get the image path? I set the contents of the WebView using the LoadHtml member function.

B4X:
WebView1.LoadHtml("<b>Test</b><br><img src='Chrysanthemum.jpg'>")

How can I get the path of the embeded image that I have put in my project?
 

klaus

Expert
Licensed User
Longtime User
You shouldn't check the the checkbox at the left, this is used for removing files !
The path name for the embedded files is the variable File.DirAssets.
So you code should look like this:
B4X:
WebView1.LoadHtml("<b>Test</b><br><img src='" & File.DirAssets & "/Chrysanthemum.jpg'>")
Best regards.
 
Upvote 0

kormos

Member
Licensed User
Longtime User
I tryed it but it displayes a blue box with a question mark inside. I suppose this is image is displayed there in order to inform me that the control did not find the image.
 
Upvote 0

susu

Well-Known Member
Licensed User
Longtime User
Try this code:
WebView1.LoadHtml("<b>Test</b><br><img src='file:///android_asset/Chrysanthemum.jpg'>")
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I had a look at the WebView help and saw that to access files in the assets folder the code should look like the following:
B4X:
WebView1.LoadHtml("<b>Test</b><br><img src='file:///android_asset/Chrysanthemum.jpg'>")
I'm not shure if the beginning of your html text is correct.

Perhaps you should use:
B4X:
[COLOR=#000000]WebView1.LoadHtml([/COLOR][COLOR=#800000]"[/COLOR][COLOR=#800000]<html><body><img src='file:///android_asset/[/COLOR]chrysanthemum.jpg[COLOR=#800000]'/></body></html>[/COLOR][COLOR=#800000]"[/COLOR][COLOR=#000000])[/COLOR]
Best regards.
 
Upvote 0

kormos

Member
Licensed User
Longtime User
After testing all the options the only way that worked for my project is the following.

B4X:
WebView1.LoadHtml("<html><body><img src='file:///android_asset/chrysanthemum.jpg'/></body></html>")

I also want to make one more question if you can help my. If VB.NET you can place the " character in a string by typing it twice. For expample you can have a string variable like this:

B4X:
Dim MyString as String = "My name is ""Manos"" and I am from Greece"

This has as a result to store in the string the following value:

My name is "Manos" and I am from Greece

Also there is a constant for changing line in a string called vbCrLf. Is there a way to put the CrLf in a string like a constant or like a code inside the string.
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
This should work:

B4X:
Dim MyString as String 

MyString = "My name is " & QUOTE & "Manos" & QUOTE & " and I am from Greece"

There's a constant CRLF in B4A

B4X:
MsgBox("Hello" & CRLF & "There", "")
 
Upvote 0
Top