Load the image saved in sdcard in webview

后端 未结 3 1352
醉话见心
醉话见心 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 05:50

    WebViews can display HTML not images. You either need to use an ImageView or generate some HTML with an image tag that displays your picture. If it needs to be dynamic you can generate it as a String and use the loadData() method to display it.

    Edit: You're going to want something like this in your html String.

    String base = Environment.getExternalStorageDirectory().getAbsolutePath().toString(); 
    String imagePath = base + "/test.jpg"; 
    String html = ("
                    
                    
                    
                    
                    
                    
                    "); 
    mWebView.loadData(html, "text/html","utf-8");
    

提交回复
热议问题