且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是什么文件:///android_asset/www/index.html是什么意思?

更新时间:2023-11-17 22:38:22

文件:/// 是一个URI(统一资源标识符),简单地从标准的URI区分我们都知道的非常清楚 - 的http://

file:/// is a URI (Uniform Resource Identifier) that simply distinguishes from the standard URI that we all know of too well - http://.

它确实意味着一个绝对路径指向在任何环境下的根目录,但在Android的背景下,这是一个约定,告诉了Android运行时间说的在这里,目录 WWW 有一个名为 index.html的位于资产文件夹中项目的。

It does imply an absolute path name pointing to the root directory in any environment, but in the context of Android, it's a convention to tell the Android run-time to say "Here, the directory www has a file called index.html located in the assets folder in the root of the project".

这就是资产是如何在运行时加载,例如的WebView 插件会确切地知道在哪里指定加载嵌入的资源文件中的文件:/// URI

That is how assets are loaded at runtime, for example, a WebView widget would know exactly where to load the embedded resource file by specifying the file:/// URI.

考虑code例如:

WebView webViewer = (WebView) findViewById(R.id.webViewer);
webView.loadUrl("file:///android_asset/www/index.html");

一个很容易犯的错误这里是这样,有些人会就推断为文件:/// android_assets ,注意资产的URI复数,不知道为什么嵌入的资源不工作!

A very easy mistake to make here is this, some would infer it to as file:///android_assets, notice the plural of assets in the URI and wonder why the embedded resource is not working!