I just want to show a local image with some texts and other stuffs in my webview in android.
i.e i have webview s.t.
WebView mWebView = (WebView) otherappView.findViewById(R.id.webView1);
String summary =readRawTextFile(context, R.raw.abc);
mWebView.loadData(summary, "text/html", null);
and in abc.html file what should i write for src tag of image (???? part)
<img width="48" height="48" src="??????" class="attachment-48x48 wp-post-image" alt="" title="analogklasik48" />
p.s. the project is a library project so i dont want to use asset folder
p.s. file:///android_res/drawable/image.png doesnt work
If you want to put an image from the drawable folder, you should convert it to base64 and then put in your html string:
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.my_drawable);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
String base64Image = Base64.encodeToString(baos.toByteArray(), Base64.DEFAULT);
String imgHtml = "<img src=\"data:image/jpg;base64," + base64Image + "\"/>";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With