How to save data to the ML2 Filesystem

Saving frames as images in an Android app is a common task, but it's important to use the appropriate methods provided by the Android framework rather than standard C++ techniques like ofstream. Android has specific file system access rules, especially starting with Android 10 (API level 29) due to scoped storage, which can prevent traditional file I/O from working as expected.

Here's a general approach to saving images on Android:

    • Request the necessary permissions - in your AndroidManifest.xml file, such as WRITE_EXTERNAL_STORAGE
  1. Use Android's MediaStore API to save images. This API provides a standard way to save images to the shared storage without needing to request file permissions.
  2. Handle file paths and URIs correctly. Android 10 introduces scoped storage, which means you can't directly access file paths. Instead, you should use URIs provided by the MediaStore API.

For more detailed guidance, you might want to check out Android's official documentation or look for tutorials on using the MediaStore API to save images.