显示图像从SD卡与web视图不工作 [英] showing image from sdcard with webview not working
问题描述
我已经下载map750.png文件SD卡的根目录,但是当我试图用文字的WebView中表现出来,只有文字显示。你能帮我找到什么是错的,在code?谢谢。
的setContentView(R.layout.webview);
mWebView =(web视图)findViewById(R.id.webview);
。mWebView.getSettings()setAllowFileAccess(真正的);
mWebView.getSettings()setJavaScriptEnabled(真)。
。mWebView.getSettings()setBuiltInZoomControls(真正的);
字符串的HTML =< HTML>< HEAD>< /头><身体GT;< P>你好< / P>< IMG SRC = \文件://mnt/sdcard/map750.png \ ALT = \alternativo \/>< /身体GT;< / HTML>中;
mWebView.loadData(HTML,text / html的,UTF-8);
我编辑的职位,以增加该解决方案由oneilse14建议,谢谢!
的setContentView(R.layout.webview);
mWebView =(web视图)findViewById(R.id.webview);
。mWebView.getSettings()setAllowFileAccess(真正的);
mWebView.getSettings()setJavaScriptEnabled(真)。
。mWebView.getSettings()setBuiltInZoomControls(真正的);
字符串的HTML =< HTML>< HEAD>< /头><身体GT;< P>你好< / P>< IMG SRC = \文件://mnt/sdcard/map750.png \ ALT = \alternativo \/>< /身体GT;< / HTML>中;
mWebView.loadDataWithBaseURL(,HTML,text / html的,UTF-8,);
退房loadDataWithBaseURL()在开发者文档
http://developer.android.com/reference/android/webkit/ WebView.html
loadData()有什么可以显示一定的限制。这种方法能够显示本地设备的文件就像你正在尝试做的。
I have downloaded map750.png file in the root of sdcard, but when I try to show it within a webview with some text, only the text is shown. Could you help me to find what is wrong in the code? thanks.
setContentView(R.layout.webview);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setAllowFileAccess(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setBuiltInZoomControls(true);
String html = "<html><head></head><body><p>hello</p><img src=\"file://mnt/sdcard/map750.png\" alt=\"alternativo\" /></body></html>";
mWebView.loadData(html, "text/html","utf-8");
I edit the post to add the solution suggested by oneilse14, thanks!!
setContentView(R.layout.webview);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setAllowFileAccess(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setBuiltInZoomControls(true);
String html = "<html><head></head><body><p>hello</p><img src=\"file://mnt/sdcard/map750.png\" alt=\"alternativo\" /></body></html>";
mWebView.loadDataWithBaseURL("", html, "text/html", "utf-8", "");
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.
这篇关于显示图像从SD卡与web视图不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!