• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Saving generic files in latest Android SDK to shared storage

artik

Lurker
I develop an open source app (OpenLiveStacker) the communicates with external USB camera - astronomy device.

It mostly written in C++ (as it does not run on Android only) with small Java/Android wrapper the manages it.
One of the things I need to do is to save collected images (tiff files) and meta-data + logs on each and every image.

Till now I created directory DCIM/OpenLiveStacker and some sub-directories for various data files: images, json, text, csv - all the data
I collect from the camera and it can be used later for processing offline with various tools.
I asked read/write permissions and it worked wee.

When I try to upgrade to latest targetSDK (33) - so I can publish it on Google play store it all stops working. I don't have permissions to write there. From what I understand requesting MANAGE_EXTERNAL_STORAGE permission is not going to work on Google play

I started reading about about Scoped Storage but from what I understand I still can't access it via Java File or C++ fstream/fopen but I need to use specific API and it is limited to specific media types. Do I understand correctly?

Is there any way to save generic files to storage visible and accessible easily to user and I can access with standard API?
 
To save generic files to shared storage in the latest Android SDK (Android 10+):

  1. Request write and read external storage permissions.
  2. Use the Storage Access Framework (SAF) to pick a location.
  3. Handle the selected location's URI and write your file using a ContentResolver.
 
> write your file using a ContentResolver

I mean using `std::fstream` of `FILE *fopen` since the code that access/saves files is NDK and cross platform
 
I actually solved my problem by saving to Android/media via getExternalMediaDirs() - at least I can access it from file manager and write files from standard API.
 
Back
Top Bottom