java 路径“file:///android_asset/”记录在哪里?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13638892/
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-10-31 13:28:43  来源:igfitidea点击:

Where is the path "file:///android_asset/" documented?

javaandroid

提问by Cornstalks

There's a number of pages on the Internet talking about the "file:///android_asset/" path (sometimes with an sappended to the end...) for accessing the assets folder. I am unable to find any kind of official or trustworthy documentation on this path/feature.

互联网上有很多页面都在讨论用于访问资产文件夹的“file:///android_asset/”路径(有时会在末尾附加一个s...)。我无法在此路径/功能上找到任何类型的官方或值得信赖的文档。

Is there any proper documentation for this path? Did the Android team document it?

这条路径是否有任何适当的文档?Android 团队是否记录了它?

采纳答案by Greg Hewgill

Strangely, I only found one hit for the following search:

奇怪的是,我在以下搜索中只找到了一个命中:

That search result is for WebSettings, which mentions the android_assetand android_respaths in passing.

该搜索结果是 for WebSettings,其中提到了android_assetandroid_res路径。

However, I'm sure I have read the "official" documentation for this before...

但是,我确定我之前已经阅读过有关此的“官方”文档......

回答by laalto

Android being open source its source code is the most accurate documentation. Here's from android.webkit.URLUtil:

Android 是开源的,它的源代码是最准确的文档。这是来自android.webkit.URLUtil

// to refer to bar.png under your package's asset/foo/ directory, use
// "file:///android_asset/foo/bar.png".
static final String ASSET_BASE = "file:///android_asset/";
// to refer to bar.png under your package's res/drawable/ directory, use
// "file:///android_res/drawable/bar.png". Use "drawable" to refer to
// "drawable-hdpi" directory as well.
static final String RESOURCE_BASE = "file:///android_res/";

回答by amoyano

I found this:

我找到了这个:

http://developer.android.com/tools/projects/index.html

http://developer.android.com/tools/projects/index.html

It provides the directory structure of a project.

它提供了项目的目录结构。

The interesting part says:

有趣的部分说:

  • assets/ This is empty. You can use it to store raw asset files. Files that you save here are compiled into an .apk file as-is, and the original filename is preserved. You can navigate this directory in the same way as a typical file system using URIs and read files as a stream of bytes using the AssetManager. For example, this is a good location for textures and game data.

  • res/ Contains application resources, such as drawable files, layout files, and string values. See Application Resources for more information.

    • anim/ For XML files that are compiled into animation objects. See the Animation resource type.

    • color/ For XML files that describe colors. See the Color Values resource type.

    • drawable/ For bitmap files (PNG, JPEG, or GIF), 9-Patch image files, and XML files that describe Drawable shapes or Drawable objects that contain multiple states (normal, pressed, or focused). See the Drawable resource type.

    • layout/ XML files that are compiled into screen layouts (or part of a screen). See the Layout resource type.

    • menu/ For XML files that define application menus. See the Menus resource type.

    • raw/ For arbitrary raw asset files. Saving asset files here instead of in the assets/ directory only differs in the way that you access them. These files are processed by aapt and must be referenced from the application using a resource identifier in the R class. For example, this is a good place for media, such as MP3 or Ogg files.

    • values/ For XML files that are compiled into many kinds of resource. Unlike other resources in the res/ directory, resources written to XML files in this folder are not referenced by the file name. Instead, the XML element type controls how the resources is defined within them are placed into the R class.

    • xml/ For miscellaneous XML files that configure application components. For example, an XML file that defines a PreferenceScreen, AppWidgetProviderInfo, or Searchability Metadata. See Application Resources for more information about configuring these application components.

  • 资产/这是空的。您可以使用它来存储原始资产文件。您在此处保存的文件将按原样编译为 .apk 文件,并保留原始文件名。您可以使用 URI 以与典型文件系统相同的方式浏览此目录,并使用 AssetManager 将文件作为字节流读取。例如,这是放置纹理和游戏数据的好位置。

  • res/ 包含应用程序资源,例如可绘制文件、布局文件和字符串值。有关更多信息,请参阅应用程序资源。

    • anim/ 用于编译成动画对象的 XML 文件。请参阅动画资源类型。

    • color/ 用于描述颜色的 XML 文件。请参阅颜色值资源类型。

    • drawable/ 对于位图文件(PNG、JPEG 或 GIF)、9-Patch 图像文件和 XML 文件,这些文件描述了包含多种状态(正常、按下或聚焦)的可绘制形状或可绘制对象。请参阅 Drawable 资源类型。

    • layout/ XML 文件被编译成屏幕布局(或屏幕的一部分)。请参阅布局资源类型。

    • menu/ 用于定义应用程序菜单的 XML 文件。请参阅菜单资源类型。

    • raw/ 用于任意原始资产文件。将资产文件保存在此处而不是在 assets/ 目录中,仅在您访问它们的方式上有所不同。这些文件由 aapt 处理,并且必须使用 R 类中的资源标识符从应用程序中引用。例如,这是存放 MP3 或 Ogg 文件等媒体的好地方。

    • values/ 用于编译成多种资源的 XML 文件。与 res/ 目录中的其他资源不同,写入此文件夹中的 XML 文件的资源不会被文件名引用。相反,XML 元素类型控制如何将其中定义的资源放置到 R 类中。

    • xml/ 用于配置应用程序组件的各种 XML 文件。例如,定义 PreferenceScreen、AppWidgetProviderInfo 或 Searchability Metadata 的 XML 文件。有关配置这些应用程序组件的更多信息,请参阅应用程序资源。