Load the image saved in sdcard in webview

后端 未结 3 1347
醉话见心
醉话见心 2020-11-29 05:14

The below code is used

mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setAllowFileAccess(true);
mWebView.getSettings().setJavaScript         


        
3条回答
  •  失恋的感觉
    2020-11-29 06:04

    mWebView = (WebView) findViewById(R.id.webview);
    mWebView.getSettings().setAllowFileAccess(true);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setBuiltInZoomControls(true);
    String base = Environment.getExternalStorageDirectory().getAbsolutePath().toString();
    String imagePath = "file://"+ base + "/test.jpg";
    String html = "";
    mWebView.loadDataWithBaseURL("", html, "text/html","utf-8", "");  
    

    This did the trick as we have to append the"prefix "file://" before any file so as to display in the webview

提交回复
热议问题