Android
android.content.res
public final class

android.content.res.AssetManager

java.lang.Object
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.

Nested Classes

Summary

Constants

      Value  
int  ACCESS_BUFFER  Mode for open(String, int): Attempt to load contents into memory, for fast small reads.  0x00000003 
int  ACCESS_RANDOM  Mode for open(String, int): Read chunks, and seek forward and backward.  0x00000001 
int  ACCESS_STREAMING  Mode for open(String, int): Read sequentially, with an occasional forward seek.  0x00000002 
int  ACCESS_UNKNOWN  Mode for open(String, int): no specific information about how data will be accessed.  0x00000000 

Public Methods

          void  close()
Close this asset manager.
    final      String[]  getLocales()
Get the locales that this asset manager contains data for.
    final      String[]  list(String path)
Return a String array of all the assets at the given path.
    final      InputStream  open(String fileName, int accessMode)
Open an asset using an explicit access mode, returning an InputStream to read its contents.
    final      InputStream  open(String fileName)
Open an asset using ACCESS_STREAMING mode.
    final      AssetFileDescriptor  openFd(String fileName)
    final      AssetFileDescriptor  openNonAssetFd(String fileName)
    final      AssetFileDescriptor  openNonAssetFd(int cookie, String fileName)
    final      XmlResourceParser  openXmlResourceParser(String fileName)
Retrieve a parser for a compiled XML file.
    final      XmlResourceParser  openXmlResourceParser(int cookie, String fileName)
Retrieve a parser for a compiled XML file.

Protected Methods

          void  finalize()
Called by the virtual machine when there are no longer any (non-weak) references to the receiver.
Methods inherited from class java.lang.Object

Details

Constants

public static final int ACCESS_BUFFER

Mode for open(String, int): Attempt to load contents into memory, for fast small reads.
Constant Value: 3 (0x00000003)

public static final int ACCESS_RANDOM

Mode for open(String, int): Read chunks, and seek forward and backward.
Constant Value: 1 (0x00000001)

public static final int ACCESS_STREAMING

Mode for open(String, int): Read sequentially, with an occasional forward seek.
Constant Value: 2 (0x00000002)

public static final int ACCESS_UNKNOWN

Mode for open(String, int): no specific information about how data will be accessed.
Constant Value: 0 (0x00000000)

Public Methods

public void close()

Close this asset manager.

public final String[] getLocales()

Get the locales that this asset manager contains data for.

public final String[] list(String path)

Return a String array of all the assets at the given path.

Parameters

path A relative path within the assets, i.e., "docs/home.html".

Returns

  • 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().

Throws

IOException

See Also

public final InputStream open(String fileName, int accessMode)

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

public final InputStream open(String fileName)

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

public final AssetFileDescriptor openFd(String fileName)

Throws

IOException

public final AssetFileDescriptor openNonAssetFd(String fileName)

Throws

IOException

public final AssetFileDescriptor openNonAssetFd(int cookie, String fileName)

Throws

IOException

public final XmlResourceParser openXmlResourceParser(String fileName)

Retrieve a parser for a compiled XML file.

Parameters

fileName The name of the file to retrieve.

Throws

IOException

public final XmlResourceParser openXmlResourceParser(int cookie, String fileName)

Retrieve a parser for a compiled XML file.

Parameters

cookie Identifier of the package to be opened.
fileName The name of the file to retrieve.

Throws

IOException

Protected Methods

protected void finalize()

Called by the virtual machine when there are no longer any (non-weak) references to the receiver. Subclasses can use this facility to guarantee that any associated resources are cleaned up before the receiver is garbage collected. Uncaught exceptions which are thrown during the running of the method cause it to terminate immediately, but are otherwise ignored.

Note: The virtual machine assumes that the implementation in class Object is empty.

Throws

Throwable
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:48