Pol Hallen
Pol Hallen

Reputation: 1862

webview and local html

I've putted a webview and with this code I use it with local html. Now, I'd like add images to this html but I don't know where put that images. Any advice?

String html = "<html><body>Hello, World!</body></html>";
String mime = "text/html";
String encoding = "utf-8";

WebView myWebView = (WebView)this.findViewById(R.id.myWebView);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.loadDataWithBaseURL(null, html, mime, encoding, null);

Upvotes: 0

Views: 122

Answers (2)

GrIsHu
GrIsHu

Reputation: 23638

If you want to add the image in the html file then you need to make the changes as below:

String html ="<html><body>Hello, World!" +
            "<img src=\"C:/Users/Public/Pictures/Sample Pictures/pulpit.jpg\" alt=\"Pulpit rock\" width=\"304\" height=\"228\" /></body></html>";

Thanks.

Upvotes: 1

Andy Res
Andy Res

Reputation: 16043

Create a html page in the in assets/ folder.
How to add images to a html file is decribed here.

Then load that page in the WebView:

webView.loadUrl("file:///android_asset/filename.html");

Upvotes: 1

Related Questions