Package android.content.res
Class AssetManager
- java.lang.Object
-
- android.content.res.AssetManager
-
- All Implemented Interfaces:
AutoCloseable
public final class AssetManager extends Object implements AutoCloseable
Provides access to an application's raw asset files; seeResourcesfor 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classAssetManager.AssetInputStream
-
Field Summary
Fields Modifier and Type Field Description static intACCESS_BUFFERMode foropen(String, int): Attempt to load contents into memory, for fast small reads.static intACCESS_RANDOMMode foropen(String, int): Read chunks, and seek forward and backward.static intACCESS_STREAMINGMode foropen(String, int): Read sequentially, with an occasional forward seek.static intACCESS_UNKNOWNMode foropen(String, int): no specific information about how data will be accessed.
-
Constructor Summary
Constructors Constructor Description AssetManager()Create a new AssetManager containing only the basic system assets.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close this asset manager.FilefindAsset(String fileName)StringgetResourceEntryName(int resid)intgetResourceIdentifier(String type, String name, String defPackage)InputStreamopen(String fileName)Open an asset using ACCESS_STREAMING mode.InputStreamopen(String fileName, int accessMode)Open an asset using an explicit access mode, returning an InputStream to read its contents.InputStreamopenNonAsset(int cookie, String fileName, int accessMode)Open a non-asset in a specified package.voidsetConfiguration(int mcc, int mnc, String locale, int orientation, int touchscreen, int density, int keyboard, int keyboardHidden, int navigation, int screenWidth, int screenHeight, int smallestScreenWidthDp, int screenWidthDp, int screenHeightDp, int screenLayout, int uiMode, int majorVersion)Change the configuation used when retrieving resources.
-
-
-
Field Detail
-
ACCESS_UNKNOWN
public static final int ACCESS_UNKNOWN
Mode foropen(String, int): no specific information about how data will be accessed.- See Also:
- Constant Field Values
-
ACCESS_RANDOM
public static final int ACCESS_RANDOM
Mode foropen(String, int): Read chunks, and seek forward and backward.- See Also:
- Constant Field Values
-
ACCESS_STREAMING
public static final int ACCESS_STREAMING
Mode foropen(String, int): Read sequentially, with an occasional forward seek.- See Also:
- Constant Field Values
-
ACCESS_BUFFER
public static final int ACCESS_BUFFER
Mode foropen(String, int): Attempt to load contents into memory, for fast small reads.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AssetManager
public AssetManager()
Create a new AssetManager containing only the basic system assets. Applications will not generally use this method, instead retrieving the appropriate asset manager withResources.getAssets(). Not for use by applications.
-
-
Method Detail
-
close
public void close()
Close this asset manager.- Specified by:
closein interfaceAutoCloseable
-
open
public final InputStream open(String fileName) throws IOException
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- The name of the asset to open. This name can be hierarchical.- Throws:
IOException- See Also:
open(String, int),#list
-
open
public final InputStream open(String fileName, int accessMode) throws IOException
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- The name of the asset to open. This name can be hierarchical.accessMode- Desired access mode for retrieving the data.- Throws:
IOException- See Also:
ACCESS_UNKNOWN,ACCESS_STREAMING,ACCESS_RANDOM,ACCESS_BUFFER,open(String),#list
-
getResourceEntryName
public final String getResourceEntryName(int resid)
-
getResourceIdentifier
public final int getResourceIdentifier(String type, String name, String defPackage)
-
setConfiguration
public final void setConfiguration(int mcc, int mnc, String locale, int orientation, int touchscreen, int density, int keyboard, int keyboardHidden, int navigation, int screenWidth, int screenHeight, int smallestScreenWidthDp, int screenWidthDp, int screenHeightDp, int screenLayout, int uiMode, int majorVersion)Change the configuation used when retrieving resources. Not for use by applications.
-
openNonAsset
public final InputStream openNonAsset(int cookie, String fileName, int accessMode) throws IOException
Open a non-asset in a specified package. Not for use by applications.- Parameters:
cookie- Identifier of the package to be opened.fileName- Name of the asset to retrieve.accessMode- Desired access mode for retrieving the data.- Throws:
IOException
-
-