Android 从设备上的外部存储目录在WebView中显示图像

Android 从设备上的外部存储目录在WebView中显示图像,android,android-webview,base-url,android-external-storage,Android,Android Webview,Base Url,Android External Storage,我想在webview中显示已从外部下载到ExternalStorageDirectory的图像。我使用以下代码将HTML作为字符串加载,基本URL设置为图像保存位置的URL: Article article = page.articles.get(0); String mime = "text/html"; String encoding = "utf-8"; String base = "file:/" + Environment.getExternalStorageDirectory()

我想在webview中显示已从外部下载到
ExternalStorageDirectory
的图像。我使用以下代码将HTML作为字符串加载,基本URL设置为图像保存位置的URL:

Article article = page.articles.get(0);

String mime = "text/html";
String encoding = "utf-8";

String base = "file:/" + Environment.getExternalStorageDirectory() + "/images_folder/";
Log.v("IMAGE", base);

webView = (WebView)rootView.findViewById(R.id.webView);
webView.setBackgroundColor(Color.TRANSPARENT);
webView.loadDataWithBaseURL(base, article.articleContent, mime, encoding, null);
这段代码在模拟器中运行良好,但当我在设备(Nexus7平板电脑)上尝试时,图像无法加载。图像肯定存储在外部存储目录中,因为它们可以使用平板电脑上的文件资源管理器找到。我想这与使用模拟存储的Nexus 7有关,但我真的不知道,调用
Environment.getExternalStorageDirectory()
每次都应该指向同一个目录

引入的html字符串非常简单,如下所示:

<html><head></head><body><img src = 'test_download1.png'></img>This is the first Article for the first page in html</body></html>
这是html第一页的第一篇文章

其中
test\u download1.png
是存储在外部存储目录中的文件。

要访问nexus 7中的SD卡,您必须编写不同的代码,因为您的代码只允许访问mnt/SD卡,而不允许访问保存图像的实际路径