是否有类似于 file:///android_asset/ 的路径指向 apps 目录?

发布于 2024-09-27 13:36:38 字数 252 浏览 4 评论 0原文

我正在使用 WebView 打开保存到应用程序的一些文件。有没有一种方法可以链接到应用程序的目录,在运行时保存的文件将在该目录中,类似于 file:///android_asset/ 的方式?我所说的链接是指 loadUrl( *path* ) 以及正在打开的文件的 HTML 标记

与此相反使用绝对路径,例如 file:///data/data/PACKAGENAME/files/

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/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无名指的心愿 2024-10-04 13:36:38

将其用于 SD 卡上的文件:

内容://com.android.htmlfileprovider

将其用于资产目录中的文件:

文件:///android_asset

另外,如果您想在 Web 视图中使用该基本目录中的所有引用,请像这样设置 baseUrl 字段,其中“baseUrl”是我上面提到的根目录:

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

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);
┼── 2024-10-04 13:36:38

从 android 2.1 开始,他们添加了

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

对 SD 卡上文件的支持,

因此:

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

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");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文