public final class AssetManager extends Object implements AutoCloseable
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.| Modifier and Type | Class and Description |
|---|---|
class |
AssetManager.AssetInputStream |
| Modifier and Type | Field and Description |
|---|---|
static int |
ACCESS_BUFFER
Mode for
open(String, int): Attempt to load contents into
memory, for fast small reads. |
static int |
ACCESS_RANDOM
Mode for
open(String, int): Read chunks, and seek forward and
backward. |
static int |
ACCESS_STREAMING
Mode for
open(String, int): Read sequentially, with an
occasional forward seek. |
static int |
ACCESS_UNKNOWN
Mode for
open(String, int): no specific information about how
data will be accessed. |
| Constructor and Description |
|---|
AssetManager()
Create a new AssetManager containing only the basic system assets.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Close this asset manager.
|
File |
findAsset(String fileName) |
String |
getResourceEntryName(int resid) |
int |
getResourceIdentifier(String type,
String name,
String defPackage) |
InputStream |
open(String fileName)
Open an asset using ACCESS_STREAMING mode.
|
InputStream |
open(String fileName,
int accessMode)
Open an asset using an explicit access mode, returning an InputStream to
read its contents.
|
InputStream |
openNonAsset(int cookie,
String fileName,
int accessMode)
Open a non-asset in a specified package.
|
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.
|
public static final int ACCESS_UNKNOWN
open(String, int): no specific information about how
data will be accessed.public static final int ACCESS_RANDOM
open(String, int): Read chunks, and seek forward and
backward.public static final int ACCESS_STREAMING
open(String, int): Read sequentially, with an
occasional forward seek.public static final int ACCESS_BUFFER
open(String, int): Attempt to load contents into
memory, for fast small reads.public AssetManager()
Resources.getAssets(). Not for
use by applications.
public void close()
close in interface AutoCloseablepublic final InputStream open(String fileName) throws IOException
fileName - The name of the asset to open. This name can be
hierarchical.IOExceptionopen(String, int),
#listpublic final InputStream open(String fileName, int accessMode) throws IOException
fileName - The name of the asset to open. This name can be
hierarchical.accessMode - Desired access mode for retrieving the data.IOExceptionACCESS_UNKNOWN,
ACCESS_STREAMING,
ACCESS_RANDOM,
ACCESS_BUFFER,
open(String),
#listpublic final String getResourceEntryName(int resid)
public final int getResourceIdentifier(String type, String name, String defPackage)
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)
public final InputStream openNonAsset(int cookie, String fileName, int accessMode) throws IOException
cookie - Identifier of the package to be opened.fileName - Name of the asset to retrieve.accessMode - Desired access mode for retrieving the data.IOException