showing image from sdcard with webview not working

孤人 提交于 2019-12-04 10:41:37

Check out loadDataWithBaseURL() in the Developer docs

http://developer.android.com/reference/android/webkit/WebView.html

loadData() has certain restrictions on what it can display. This method is able to display local device files like you are trying to do.

Try this,

        final String fileName = "file:///mnt/sdcard/1.jpg";
        final String mimeType = "text/html";
        final String encoding = "utf-8";
        final String html = "<img src=\""+fileName+"\">";
        webView.loadDataWithBaseURL("", html, mimeType, encoding, "");

Note that the access using the file:// schema can fail due security restrictions.

Another approach is to use the URI of a ContentProvider that handles the local file access. Overwrite openFile(Uri, String) in a subclass of ContentProvider for this approach.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!