Handling user settings on file, how?

Ok, I created my first APP, it runs on the Virtual and also a Real phone. :slight_smile: Now I added the properties file but it doesn’t get saved or maybe even created. I tried to search the file but couldn’t find it… maybe is the way Android works, so I need to learn that…

PropertiesFile::Options propOptions;
propOptions.applicationName = "7 Segments";
configFile = File(File::getSpecialLocation(File::SpecialLocationType::commonDocumentsDirectory).getFullPathName() + "Seven Segments Settings.xml");
userSettings = new PropertiesFile(configFile, propOptions);

To access files outside the sandbox, the app needs to ask for permission using the RuntimePermissions class. On most folders I was using, including userDocumentsDirectory and userMusicDirectory I needed to request RuntimePermissions::writeExternalStorage

I would try different locations, if you can find some inside the app’s sandbox, maybe userApplicationDataDirectory, but I am not an Android expert.

1 Like

Oh yeah, thank you so much!


Android is tricky, here is the folder i tried, it seems like w/o success

For android and other mobile platforms have a look into the RuntimePermissions class (am on mobile, hence no link… you should be able to find it in the docs)

Thank you Daniel, with RuntimePermission and following code, file has been created successfully.
File configFile = File("/sdcard/Download/MySettings.xml");
configFile.create();

Interesting!
Could you post the complete (relevant) code?
For me the only folder I could use was the one you’d get with userDocumentsDirectory.

Another question would be:
Do we need to RuntimePermissions::request

  • once during app init
  • each time inside the same scope we want to deal with files
  • on the same thread we want to deal with files later (note the callback is called synchonously once permission was granted)

I’d love to be able to use the download folder… :slight_smile: