Class AssetManager

  • All Implemented Interfaces:
    AutoCloseable

    public final class AssetManager
    extends Object
    implements AutoCloseable
    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.
    • 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 with Resources.getAssets(). Not for use by applications.
    • Method Detail

      • close

        public void close()
        Close this asset manager.
        Specified by:
        close in interface AutoCloseable
      • 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
      • findAsset

        public final File findAsset​(String fileName)
      • 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