Reputation: 182
I'm trying to load sdcard's image file to assets folder's html file using javascript.If in path i put image src as weblink then it loads the link but if I give image src path as sdacrd file path it doesn't load anything
path= Environment.getExternalStorageDirectory()+ File.separator+"aa.jpg";
webview=(WebView)findViewById(R.id.webView);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("file:///android_asset/info.html");
webview.setWebViewClient(new WebViewClient(){
public void onPageFinished(WebView view, String url){
webview.loadUrl("javascript:init('" + path + "')");
}
});
info.html
<html>
<body>
<svg>
<image id="img" clip-path="url(#user)" x="210" y="150" height="150" width="150" xlink:href="https://anyfile.jpg" />
</svg>
</body>
<script>
var imgval=document.getElementById('img');
function init($path) {
imgval.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', $path);
}
</script>
</html>
If I give sdcard path it should load from that path only. Other way I found is just copy this html file to sdcard so that image will get load but I don't want to copy it to sdcard i wanted to load it from sdcard only
Upvotes: 0
Views: 211
Reputation: 1162
Use this format to load image file from SDcard :
String base = Environment.getExternalStorageDirectory().getAbsolutePath().toString();
String imagePath = "file://"+ base + "/image_file_in_root_folder.jpg";
Upvotes: 1