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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11961975/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:18:59  来源:igfitidea点击:

What does file:///android_asset/www/index.html mean?

android

提问by Nav

I want to know what does file:///mean while loading a html file from the assets folder in android

我想知道file:///从 android 中的资产文件夹加载 html 文件是什么意思

Is it an absolute path name which points to the root directory?

它是指向根目录的绝对路径名吗?

I saw this in the tutorial for phonegap by the way.

顺便说一下,我在 phonegap 的教程中看到了这个。

回答by t0mm13b

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

file:///是一个 URI(统一资源标识符),它只是与我们都非常熟悉的标准 URI 区分开来 - http://.

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 wwwhas a file called index.htmllocated in the assetsfolder in the rootof the project".

它确实意味着一个指向任何环境中根目录的绝对路径名,但在 Android 的上下文中,它是一种约定,告诉 Android 运行时说“这里,该目录www有一个名为index.htmlassets文件,位于项目的”。

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

这就是在运行时加载资产的方式,例如,WebView小部件将通过指定file:///URI确切知道在哪里加载嵌入的资源文件。

Consider the code example:

考虑代码示例:

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

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!

这里很容易犯的一个错误是,有些人会推断它为 as file:///android_assets,注意 URI 中的资产复数,并想知道为什么嵌入的资源不起作用!

回答by Lunero

If someone uses AndroidStudio make sure that the assets folder is placed in

如果有人使用AndroidStudio,请确保将assets文件夹放在

  1. app/src/main/assets

    directory.

  1. 应用程序/源代码/主/资产

    目录。

回答by dinosaur

The URI "file:///android_asset/"points to YourProject/app/src/main/assets/.

URI"file:///android_asset/"指向YourProject/app/src/main/assets/.

Note: android_asset/uses the singular (asset) and src/main/assetsuses the plural (assets).

注意:android_asset/使用单数(资产)和src/main/assets使用复数(资产)。

Suppose you have a file YourProject/app/src/main/assets/web_thing.htmlthat you would like to display in a WebView. You can refer to it like this:

假设您有一个YourProject/app/src/main/assets/web_thing.html要在 WebView 中显示的文件。你可以这样引用它:

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

The snippet above could be located in your Activityclass, possibly in the onCreatemethod.

上面的代码片段可能位于您的Activity类中,也可能位于onCreate方法中。

Here is a guideto the overall directory structure of an android project, that helped me figure out this answer.

这是一个android 项目整体目录结构的指南,它帮助我找出了这个答案。

回答by sivi

  • It is actually called file:///android_asset/index.html

  • file:///android_assets/index.htmlwill give you a build error.

  • Consider edit the question title to

    what does file:///android_asset/index.htmlmeans

  • 它实际上被称为 file:///android_asset/index.html

  • file:///android_assets/index.html会给你一个构建错误。

  • 考虑将问题标题编辑为

    file:///android_asset/index.html是什么意思

.

.

回答by Ranger Way

It took me more than 4 hours to fix this problem. I followed the guide from http://docs.phonegap.com/en/2.1.0/guide_getting-started_android_index.md.html#Getting%20Started%20with%20Android

我花了4个多小时才解决这个问题。我遵循了http://docs.phonegap.com/en/2.1.0/guide_getting-started_android_index.md.html#Getting%20Started%20with%20Android 中的指南

I'm using Android Studio (Eclipse with ADT could not work properly because of the build problem).

我正在使用 Android Studio(由于构建问题,带有 ADT 的 Eclipse 无法正常工作)。

Solution that worked for me:

对我有用的解决方案:

  1. I put the /assets/www/index.html under app/src/main/assets directory. (take care AndroidStudio has different perspectives like Project or Android)

  2. use super.loadUrl("file:///android_asset/www/index.html"); instead of super.loadUrl("file:///android_assets/www/index.html"); (no s)

  1. 我把 /assets/www/index.html 放在 app/src/main/assets 目录下。(注意 AndroidStudio 有不同的视角,如 Project 或 Android)

  2. 使用 super.loadUrl("file:/// android_asset/www/index.html"); 而不是 super.loadUrl("file:/// android_assets/www/index.html"); (无小号

回答by Mahmoud Abdelwahab

it's file:///android_asset/... not file:///android_assets/... notice the plural of assets is wrong even if your file name is assets

它是 file:/// android_asset/... 不是 file:/// android_assets/... 请注意即使您的文件名是资产,资产的复数也是错误的