Class AndroidAssetPackage

java.lang.Object
com.massifmaps.utils.AssetPackage
com.massifmaps.utils.AndroidAssetPackage

public class AndroidAssetPackage extends AssetPackage
An asset package based on the application-bundled Android assets (the 'assets' folder of
the APK). This is the counterpart of DirAssetPackage for assets that ship with the app:
APK assets are entries inside the package, not files, so they cannot be read through a
file system path.

Note: the asset manager must be connected before an instance is created, which happens
when a MapView is constructed.
  • Constructor Details

    • AndroidAssetPackage

      public AndroidAssetPackage(String basePath) throws IOException
      Constructs an asset package from the given directory inside the application assets.
      Parameters:
      basePath - The asset directory, relative to the assets root ("" is the root itself).
      Throws:
      Exception - If the directory contains no assets.
      IOException
    • AndroidAssetPackage

      public AndroidAssetPackage(String basePath, AssetPackage baseAssetPackage) throws IOException
      Constructs an asset package from the given directory inside the application assets,
      with a fallback asset package.
      Parameters:
      basePath - The asset directory, relative to the assets root ("" is the root itself).
      baseAssetPackage - The base asset package. If an asset is not found in the assets,
      the base asset package is used.
      Throws:
      Exception - If the directory contains no assets.
      IOException
  • Method Details

    • getBasePath

      public String getBasePath()
      Returns the asset directory this package reads from.
      Returns:
      The asset directory, relative to the assets root.
    • getLocalAssetNames

      public StringVector getLocalAssetNames()
      Returns the list of assets bundled under the base path, ignoring the base asset package.
      Returns:
      The list of asset names, relative to the base path.
    • reload

      public void reload()
      Rescans the asset directory. Bundled assets cannot change while the app runs, so this is
      only needed if the asset manager was connected after this package was created.
    • getAssetNames

      public StringVector getAssetNames()
      Description copied from class: AssetPackage
      Returns list of assets in the asset package.
      All listed assets can read using loadAsset API.
      Overrides:
      getAssetNames in class AssetPackage
      Returns:
      List of asset names.
    • loadAsset

      public BinaryData loadAsset(String name)
      Description copied from class: AssetPackage
      Loads the specified asset from the asset package.
      Overrides:
      loadAsset in class AssetPackage
      Parameters:
      name - The asset name to read.
      Returns:
      Asset data, if the asset exists and was successfully read. Null pointer otherwise.