hi i want to load sdcard images to webview, here is an example for load pdf (with pdfjs (javascrip lib)) in webview:
Open PDF in a WebView
is there any way like this to load jpg,tiff,png into webview? how about excel?
Asked
Active
Viewed 660 times
-2
-
You want to open an SD Card (in an Android) with Excel (installed on an Android)?? – ashleedawg Jul 14 '18 at 10:51
-
1no, open excel file or image in webview – Jul 14 '18 at 11:01
1 Answers
1
the answer to your first question : [ How to load images from sdcard in to Webview ? ] Use this code and please read the comments :
wbView = (WebView) findViewById(R.id.wb);
String SdCard = Environment.getExternalStorageDirectory().getAbsolutePath().toString();
// Image path [List]
// Path => [/storage/emulated/0/files.jpg, png , tiff and etc ...]
String Jpg = "file://"+ SdCard + "/image1.jpg"; // First Image - Jpg format
String Png = "file://"+ SdCard + "/image2.png"; // Second Image - Png format
String Tiff = "file://"+ SdCard + "/image3.tiff"; // Third Image - Tiff format
// Load Images [WebView content]
String Html =
"<tr><td> First Image content : </td><img src=\""+Jpg+"\"height=\"130px"+"\"width=\"100%"+"\"></tr>" +
"<br/><hr>" +
"<tr><td> Second Image content : </td><img src=\""+Png+"\"height=\"130px"+"\"width=\"100%"+"\"></tr>"+
"<br/><hr>" +
"<tr><td> Third Image content : </td><img src=\""+Tiff+"\"height=\"130px"+"\"width=\"100%"+"\"></tr>";
// local html
wbView.loadDataWithBaseURL("",Html, "text/html","utf-8", "");
//wbView.loadUrl(""); <== Do not use this !
Do not forget to add these permissions in your manifest file :
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Output Image [WebView] :
And unfortunately I did not find the answer for your second question [Excel] , if I find a way, I'll tell you :)
Good luck.

Siros Baghban
- 406
- 4
- 7