Documentation
¶
Overview ¶
Example: AAssetManager API overview and directory iteration.
Demonstrates the full ndk/asset API surface: opening assets by path, reading content, querying length and allocation state, seeking within an asset, and iterating directories.
AAssetManager lifecycle on Android:
- Obtain the AAssetManager pointer from the Activity's ANativeActivity struct (activity.AssetManager in ndk/activity). The manager is owned by the framework and must not be freed by application code.
- Open an individual asset with Manager.Open(filename, mode). The filename is relative to the APK's "assets/" directory (e.g. "textures/wood.png"). The mode controls how the NDK buffers the data.
- Read the asset with Asset.Read, or access it directly via Asset.Buffer (only valid when opened with Buffer mode). Query the size with Asset.Length / Asset.Length64 and the unread portion with Asset.RemainingLength / Asset.RemainingLength64. Reposition with Asset.Seek using standard SEEK_SET/SEEK_CUR/SEEK_END whence values.
- Close the asset with Asset.Close when finished.
Directory iteration:
- Open a directory with Manager.OpenDir(dirName). Pass an empty string to list the root of the assets/ tree, or a subdirectory path.
- Call Dir.NextFileName repeatedly. Each call returns the next filename as a string, or "" when the listing is exhausted.
- Call Dir.Rewind to reset the iterator back to the first entry.
- Close with Dir.Close when finished.
This program prints all Mode constants and documents the usage patterns in executable form. It cannot run without a real AAssetManager obtained from an Android Activity.
This program must run on an Android device.
Click to show internal directories.
Click to hide internal directories.