AssetManager
class AssetManager : AutoCloseable
| kotlin.Any | |
| ↳ | android.content.res.AssetManager |
Provides access to an application's raw asset files; see Resources for the way most applications will want to retrieve their resource data. This class presents a lower-level API that allows you to open and read raw files that have been bundled with the application as a simple stream of bytes.
Summary
| Nested classes | |
|---|---|
| Constants | |
|---|---|
| static Int |
Mode for |
| static Int |
Mode for |
| static Int |
Mode for |
| static Int |
Mode for |
| Public methods | |
|---|---|
| Unit |
close()Close this asset manager. |
| Array<String!>! |
Get the locales that this asset manager contains data for. |
| Array<String!>? |
Return a String array of all the assets at the given path. |
| InputStream |
Open an asset using ACCESS_STREAMING mode. |
| InputStream |
Open an asset using an explicit access mode, returning an InputStream to read its contents. |
| AssetFileDescriptor |
Open an uncompressed asset by mmapping it and returning an |
| AssetFileDescriptor |
openNonAssetFd(cookie: Int, fileName: String)Open a non-asset as an asset by mmapping it and returning an |
| AssetFileDescriptor |
openNonAssetFd(fileName: String)Open a non-asset as an asset by mmapping it and returning an |
| XmlResourceParser |
openXmlResourceParser(cookie: Int, fileName: String)Retrieve a parser for a compiled XML file. |
| XmlResourceParser |
openXmlResourceParser(fileName: String)Retrieve a parser for a compiled XML file. |
| Protected methods | |
|---|---|
| Unit |
finalize() |
Constants
ACCESS_BUFFER
static val ACCESS_BUFFER: Int
Mode for open(java.lang.String,int): Attempt to load contents into memory, for fast small reads.
Value: 3ACCESS_RANDOM
static val ACCESS_RANDOM: Int
Mode for open(java.lang.String,int): Read chunks, and seek forward and backward.
Value: 1ACCESS_STREAMING
static val ACCESS_STREAMING: Int
Mode for open(java.lang.String,int): Read sequentially, with an occasional forward seek.
Value: 2ACCESS_UNKNOWN
static val ACCESS_UNKNOWN: Int
Mode for open(java.lang.String,int): no specific information about how data will be accessed.
Value: 0Public methods
close
fun close(): Unit
Close this asset manager.
| Exceptions | |
|---|---|
java.lang.Exception |
if this resource cannot be closed |
getLocales
fun getLocales(): Array<String!>!
Get the locales that this asset manager contains data for.
On SDK 21 (Android 5.0: Lollipop) and above, Locale strings are valid BCP-47 language tags and can be parsed using Locale.forLanguageTag(String).
On SDK 20 (Android 4.4W: KitKat for watches) and below, locale strings are of the form ll_CC where ll is a two letter language code, and CC is a two letter country code.
list
fun list(path: String): Array<String!>?
Return a String array of all the assets at the given path.
| Parameters | |
|---|---|
path |
String: A relative path within the assets, i.e., "docs/home.html". This value cannot be null. |
| Return | |
|---|---|
Array<String!>? |
String[] Array of strings, one for each asset. These file names are relative to 'path'. You can open the file by concatenating 'path' and a name in the returned string (via File) and passing that to open(). This value may be null. |
See Also
open
fun open(fileName: String): InputStream
Open an asset using ACCESS_STREAMING mode. This provides access to files that have been bundled with an application as assets -- that is, files placed in to the "assets" directory.
| Parameters | |
|---|---|
fileName |
String: The name of the asset to open. This name can be hierarchical. This value cannot be null. |
| Return | |
|---|---|
InputStream |
This value cannot be null. |
See Also
open
fun open(
fileName: String,
accessMode: Int
): InputStream
Open an asset using an explicit access mode, returning an InputStream to read its contents. This provides access to files that have been bundled with an application as assets -- that is, files placed in to the "assets" directory.
| Parameters | |
|---|---|
fileName |
String: The name of the asset to open. This name can be hierarchical. This value cannot be null. |
accessMode |
Int: Desired access mode for retrieving the data. |
| Return | |
|---|---|
InputStream |
This value cannot be null. |
openFd
fun openFd(fileName: String): AssetFileDescriptor
Open an uncompressed asset by mmapping it and returning an AssetFileDescriptor. This provides access to files that have been bundled with an application as assets -- that is, files placed in to the "assets" directory. The asset must be uncompressed, or an exception will be thrown.
| Parameters | |
|---|---|
fileName |
String: The name of the asset to open. This name can be hierarchical. This value cannot be null. |
| Return | |
|---|---|
AssetFileDescriptor |
An open AssetFileDescriptor. This value cannot be null. |
openNonAssetFd
fun openNonAssetFd(
cookie: Int,
fileName: String
): AssetFileDescriptor
Open a non-asset as an asset by mmapping it and returning an AssetFileDescriptor. This provides direct access to all of the files included in an application package (not only its assets). Applications should not normally use this. The asset must not be compressed, or an exception will be thrown.
| Parameters | |
|---|---|
cookie |
Int: Identifier of the package to be opened. |
fileName |
String: Name of the asset to retrieve. This value cannot be null. |
| Return | |
|---|---|
AssetFileDescriptor |
This value cannot be null. |
openNonAssetFd
fun openNonAssetFd(fileName: String): AssetFileDescriptor
Open a non-asset as an asset by mmapping it and returning an AssetFileDescriptor. This provides direct access to all of the files included in an application package (not only its assets). Applications should not normally use this. The asset must not be compressed, or an exception will be thrown.
| Parameters | |
|---|---|
fileName |
String: Name of the asset to retrieve. This value cannot be null. |
| Return | |
|---|---|
AssetFileDescriptor |
This value cannot be null. |
openXmlResourceParser
fun openXmlResourceParser(
cookie: Int,
fileName: String
): XmlResourceParser
Retrieve a parser for a compiled XML file.
| Parameters | |
|---|---|
cookie |
Int: Identifier of the package to be opened. |
fileName |
String: The name of the file to retrieve. This value cannot be null. |
| Return | |
|---|---|
XmlResourceParser |
This value cannot be null. |
openXmlResourceParser
fun openXmlResourceParser(fileName: String): XmlResourceParser
Retrieve a parser for a compiled XML file.
| Parameters | |
|---|---|
fileName |
String: The name of the file to retrieve. This value cannot be null. |
| Return | |
|---|---|
XmlResourceParser |
This value cannot be null. |
Protected methods
finalize
protected fun finalize(): Unit
| Exceptions | |
|---|---|
java.lang.Throwable |
the Exception raised by this method |