2011-03-07 33 views
0

請幫我解決這個文件路徑衝突:Windows和Android之間的衝突?

如你所知,許多HTML頁面中使用相對路徑開始以「/」爲鏈接標籤的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內容。任何解決方案

回答

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/哪裏文件在你的資源文件夾。

+0

所以我需要把我的CSS文件放在資產文件夾中? – vnshetty

+0

如果它只引用資產文件夾,那麼爲什麼它爲href = links/style.css而不是爲href =/links/style.css? TIA – vnshetty

+0

由於包含子目錄的相對URL不能包含前面的斜槓:http://www.webreference.com/html/tutorial2/3.html –