The below code is used
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setAllowFileAccess(true);
mWebView.getSettings().setJavaScript
I tried the methods mentioned before with no success, so this are the options that worked for me to load an image from the external storage:
Load the image directly into the WebView.
Supossing that i have an image called image.jpg inside the root of the external storage directory (in my case /storage/emulated/0/image.jpg) .
String pathExternalStorage = Environment.getExternalStorageDirectory().getAbsolutePath().toString();
String imagePath = pathExternalStorage + "/" + "imagen.jpg";
/*
//We can chek if the file really exists.
File archivo = new File(imagePath);
if(archivo.exists()){
Log.i("TAG" , "EXISTS " + imagePath);
}else{
Log.e("TAG" , "DOESN´T EXISTS " +imagePath );
}
*/
String imagePath = "file://" + imagePath;
webView.loadUrl(imagePath);
Loading the image using a html template to load into theWebView.
String pathExternalStorage = Environment.getExternalStorageDirectory().getAbsolutePath().toString();
String imagePath = pathExternalStorage + "/" + "image.jpg";
String imagePathWV = "file://" + imagePath;
String html = ("
");
webView.loadDataWithBaseURL(null, html, "text/html","utf-8",null);