Android Question HTML string and image

Paperinik

Member
Licensed User
Longtime User
In my app I have an http server, and http code is saved in a file in a DirDefaultExternal folder.
I used DirDefaultExternal because I need to change content quickly using a text editor.

Everything works fine until I decide to add an image to my webpage saved in the same folder of html file, because I dont know how to point to image inside html code.
I searched inside forum and I tried some solution without success...

I used this code :

This in b4x http server to send html file::
SendPage(File.ReadString(File.DirDefaultExternal,"pagina.html"))

This is simple html code I tried to send image:
<!doctype html>
<html>
<head>
    <title>Title</title>
</head>
<body>

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<p><img src= 'file://${File.DirDefaultExternal}/image.jpeg' alt="logo" width="30%" height="30%"/></p>

</body>
</html>

but in webpage, only text is showed
 

Shelby

Well-Known Member
Licensed User
Longtime User
I'm not positive this will help you, but here's an example of a displayed image on my website.
<img src="George112.tiny.jpg" alt="Slide 1"/>

By the way, on any webpage there is usually an option to click "view page source" when you right-click on a page (you might have to right-click on several areas to see the desired option). Then you can see a lot of code that makes up the webpage.
 
Last edited:
Upvote 0

Paperinik

Member
Licensed User
Longtime User
I'm not positive this will help you, but here's an example of a displayed image on my website.
<img src="George112.tiny.jpg" alt="Slide 1"/>

By the way, on any webpage there is usually an option to click "view page source" when you right-click on a page (you might have to right-click on several areas to see the desired option). Then you can see a lot of code that makes up the webpage.
Thank you for reply, but my code my work correctly (image included) if loaded locally on a web browser... Problem is address android to correctly find image.
 
Upvote 0

Ivica Golubovic

Active Member
Licensed User
Should I try on a different sdk?
Thank you for reply, but my code my work correctly (image included) if loaded locally on a web browser... Problem is address android to correctly find image.
First, since SDK 29 and the introduction of Scoped Storage, File.DirDefaultExternall should be avoided. You need to use the FileProvider class and place the files in a shared folder. Also, you should generate Uri for the file from the FileProvider class. Only after that, if that doesn't help, you should look for other solutions.
 
Upvote 0
Top