WebView with custom HTML and local images

2 votes · 1 comment

How-to use a WebView with custom HTML from a string, which references a local image. For the webview to find the image, you need to place it into the directory /assets/ (you probably need to create this directory).

raw ·
copy
· download
/** * This code loads a custom HTML from a string which references a local image * - for this to work, simply place the image in the directory /assets/ */ public void loadHTML() { final String mimeType = "text/html"; final String encoding = "utf-8"; final String html = "<h1>Header</h1><p>Custom HTML</p><p><img src=\\"file:///android_asset/image1.jpg\\" /></p>"; WebView wv = (WebView) findViewById(R.id.wv1); wv.loadDataWithBaseURL("fake://not/needed", html, mimeType, encoding, ""); }
Add a comment

1 Comment

Hello! Base klooper in place of my english jer, buti very nice re say gJ$)Kd!!!.

Reply · Oct. 4, 2009, 5:51 a.m.