Conflict between Windows and Android?

做~自己de王妃 提交于 2019-12-24 21:28:16

问题


Please help me solve this file path conflict:

As you know, many HTML pages use relative paths starting with a "/" for the href attribute of link tags. For example: link href="/links/style.css".

In my code, I'm using loadDataWithBaseURL for a WebView to set a relative path name. If I give like this:

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

Result: No effect in WebView because (I felt) it takes two '/' while appending to pathname.

If I edit my HTML page by removing the first "/" from the href tag, then the WebView renders properly.

But my problem is that I don't want to edit HTML content as above. Any solution?


回答1:


Javadoc of loadDataWithBaseURL states:

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

So basically only allowed URL for file:/// scheme is file:///android_asset/ where files are in your asset folder.



来源:https://stackoverflow.com/questions/5220026/conflict-between-windows-and-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!