The second Android 11 Developer Preview is now available, test it out and share your feedback.

DirectoryAssetsProvider

public class DirectoryAssetsProvider
extends Object implements AssetsProvider

java.lang.Object
   ↳ android.content.res.loader.DirectoryAssetsProvider


A AssetsProvider that searches a directory for assets. Assumes that resource paths are resolvable child paths of the root directory passed in.

Summary

Public constructors

DirectoryAssetsProvider(File directory)

Creates a DirectoryAssetsProvider with given root directory.

Public methods

File findFile(String path)

Finds the file relative to the root directory.

File getDirectory()
InputStream loadAsset(String path, int accessMode)

Callback that allows the value of a file-based resources or asset to be specified or overridden.

ParcelFileDescriptor loadAssetParcelFd(String path)

ParcelFileDescriptor variant of loadAsset(java.lang.String, int).

Inherited methods

Public constructors

DirectoryAssetsProvider

public DirectoryAssetsProvider (File directory)

Creates a DirectoryAssetsProvider with given root directory.

Parameters
directory File: the root directory to resolve files from This value must never be null.

Public methods

findFile

public File findFile (String path)

Finds the file relative to the root directory.

Parameters
path String: the relative path of the file This value must never be null.

Returns
File This value may be null.

getDirectory

public File getDirectory ()

Returns
File This value will never be null.

loadAsset

public InputStream loadAsset (String path, 
                int accessMode)

Callback that allows the value of a file-based resources or asset to be specified or overridden.

There are two situations in which this method will be called:

If the value retrieved from this callback is null, AssetManager will attempt to find the file-based resource or asset within the APK provided by the ResourcesProvider this instance is associated with.

Parameters
path String: This value must never be null.

accessMode int: the AssetManager access mode

Returns
InputStream This value may be null.

Throws
IOException

loadAssetParcelFd

public ParcelFileDescriptor loadAssetParcelFd (String path)

ParcelFileDescriptor variant of loadAsset(java.lang.String, int).

Parameters
path String: This value must never be null.

Returns
ParcelFileDescriptor This value may be null.

Throws
IOException