1

我想在已从外部下载到ExternalStorageDirectory. 我正在使用以下代码将 HTML 作为字符串加载,其中基本 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);

此代码在模拟器中运行良好,但是当我在设备(Nexus 7 平板电脑)上尝试时,图像不会加载。该图像肯定存储在外部存储目录中,因为可以使用平板电脑上的文件资源管理器找到它们。我想这与使用模拟存储的 Nexus 7 有关,但我真的不知道,调用Environment.getExternalStorageDirectory()应该每次都指向同一个目录。

引入的 html String 非常简单,如下所示:

<html><head></head><body><img src = 'test_download1.png'></img>This is the first Article for the first page in html</body></html>

test_download1.png存储在外部存储目录中的文件在哪里。

4

1 回答 1

0

要在 nexus 7 中访问 SDCARD,您必须编写不同的代码,因为您的代码只能访问 mnt/sdcard,而不是保存图像的实际路径。

在 nexus 7 中访问 SDCARD 的代码

于 2013-08-05T14:07:22.590 回答