Is there a path similar to file:///android_asset/ that points to the apps directory?

你。 提交于 2019-12-03 13:01:40

问题


I'm using a WebView to open some files saved to the app. Is there a way to link to the app's directory where files saved at runtime would be, in a similar way that file:///android_asset/ does? By link I mean loadUrl( *path* ) and also in the HTML markup of the file being opened <img src="*path*" />

As oppose to using an absolute path like file:///data/data/PACKAGENAME/files/


回答1:


Use this for files on the SD card:

content://com.android.htmlfileprovider

Use this for files in your assets directory:

file:///android_asset

Also, if you want to have all your references in your web view use that base directory set the baseUrl field like this, where "baseUrl" is the root directory as I mentioned above:

webview.loadDataWithBaseURL(
        baseUrl, htmlText, "text/html", "UTF-8", null);



回答2:


from android 2.1, they've added the

"file:///sdcard/..."

support for files on the sdcard

so :

loadUrl("file:///sdcard/path/to/my/file.html");


来源:https://stackoverflow.com/questions/3921274/is-there-a-path-similar-to-file-android-asset-that-points-to-the-apps-direct

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