Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Development: Using Image From Assets In A WebView's HTML

In my app I'm making a basic HTML help document. I wanted my app's logo in the HTML img tag itself, but I don't know how I'd reference to the logo which will be stored in assets.

Is this possible, if so how?

Thanks for the help!

like image 488
AlexPriceAP Avatar asked Sep 23 '10 15:09

AlexPriceAP


4 Answers

Put your Logo into the assets directory eg: assets/logo.png

Then load your html with:

webView.loadDataWithBaseURL("file:///android_asset/", htmlData, "text/html", "utf-8", null);

Reference your img like:

<img src="logo.png">
like image 198
spatialist Avatar answered Nov 02 '22 10:11

spatialist


Store the images in assets folder:

enter image description here

Read the image in the html from assets with file:///android_asset/

for example:

String sHtmlTemplate = "<html><head></head><body><img src=\"file:///android_asset/img/mybadge.png\"></body></html>";

load inside the WebView:

webView.loadDataWithBaseURL(null, sHtmlTemplate, "text/html", "utf-8",null);
like image 43
Jorgesys Avatar answered Nov 02 '22 09:11

Jorgesys


You can reference assets with this URL syntax:

file:///android_asset/YourAssetFilename
like image 6
Robert Nekic Avatar answered Nov 02 '22 10:11

Robert Nekic


dump them into assets folder and just put in the html

<img src="filename.png">

simple as that

like image 6
Record413123 Avatar answered Nov 02 '22 10:11

Record413123