Windows和Android之间的冲突?

时间:2011-03-07 13:00:27

标签: android path filesystems

请帮我解决这个文件路径冲突:

如您所知,许多HTML页面使用以“/”开头的相对路径作为 link 标记的href属性。例如:link href="/links/style.css"

在我的代码中,我使用loadDataWithBaseURL为WebView设置相对路径名。如果我这样给:

String webContent=//whole html page;
mWebView.loadDataWithBaseURL("file:///sdcard/mibook/pg90/",new String(webContent), "text/html", "UTF-8","" );

结果:在WebView中没有效果,因为(我觉得)在追加路径名时需要两个'/'

如果我通过从href标记中删除第一个“/”来编辑我的HTML页面,那么WebView会正确呈现。

但我的问题是我不想像上面那样编辑HTML内容。任何解决方案?

1 个答案:

答案 0 :(得分:0)

loadDataWithBaseURL州的Javadoc:

Note for post 1.0. Due to the change in the WebKit, the access to asset files through   
"file:///android_asset/" for the sub resources is more restricted. If you provide null 
or empty string as baseUrl, you won't be able to access asset files. If the baseUrl is
anything other than http(s)/ftp(s)/about/javascript as scheme, you can access asset 
files for sub resources

所以基本上只允许file:///方案的网址为file:///android_asset/,其中文件位于资产文件夹中。