Save settings lazarus / 43-Android ---------------------------------------------------------------------- eMarc · 2012-10-01 11:07 Hello. I have tried several approaches to save settings on my Android application, but I can't succeed. I try to use a INI File and TIniFile class, but the application crashes when trying to read/write the settings. If I try to use TRegistryIniFile class (you can maintain your existing code, but it will save/read your settings on the registry instead of an INI File), it doesn't crash, but it does nothing. Finally, when I try to use TRegistry class, the application crashes (I though that TRegistry class was supposed to save settings on an XML file for Linux environments). What approach would you better suggest for saving/reading settings on an Android application. Thank you. ---------------------------------------------------------------------- eMarc · 2012-10-01 11:19 I already have tried to add android.permission.WRITE_SETTINGS permissions to my APK, but it doesn't seem to help. ---------------------------------------------------------------------- eMarc · 2012-10-01 12:07 I even try to use a plain file (through TStringList Class) and the application crash. Code: [Select]  Cfg := TStringList.Create;   if FileExists(ExtractFilePath(Application.ExeName) + 'Config.txt') then begin     Cfg.LoadFromFile(ExtractFilePath(Application.ExeName) + 'Config.txt');   end;   Cfg.Values['Size'] := txtSize.Text;   Cfg.SaveToFile(ExtractFilePath(Application.ExeName) + 'Config.txt');   Cfg.Free; It works fine on Windows (nonandroidlcltest.lpi) but crashes on Android. I suppose it's a file permissions problem. ExtractFilePath(Application.ExeName) gets '/system/bin/'. ¿ What folder I'm supposed to use instead of the application path folder ?. ---------------------------------------------------------------------- eMarc · 2012-10-01 12:36 My fault. TIniFile Class and TStringList Class works perfectly on Android. My problem was that I was trying to save settings on a file on the application folder (which was /system/bin). Saving settings to /sdcard/Downlad/Config.ini works perfectly. By the way, ¿ which folder is supposed to be better for holding our settings ?. Thank you. ---------------------------------------------------------------------- zariq · 2012-10-01 13:08 It's something like  /data/data/com.yourdomain.YourApp/files. Shouldn't really be hard coding the path anyway. There's a method getfilesdir which returns the location, but no idea how to use it from lazarus. ---------------------------------------------------------------------- Laksen · 2012-10-01 13:34 GetAppConfigDir(false)+'config.ini' This should give you a working directory on all systems. No need for hardcoding ---------------------------------------------------------------------- eMarc · 2012-10-01 18:18 Quote from: Laksen on October 01, 2012, 03:34:20 pmGetAppConfigDir(false)+'config.ini' This should give you a working directory on all systems. No need for hardcoding That will be perfect. Thank you. ---------------------------------------------------------------------- eMarc · 2012-10-02 10:16 Hi. Quote from: eMarc on October 01, 2012, 08:18:39 pmQuote from: Laksen on October 01, 2012, 03:34:20 pmGetAppConfigDir(false)+'config.ini' This should give you a working directory on all systems. No need for hardcoding That will be perfect. Thank you. No luck. GetAppConfigDir(false) returns '.config/app_process' wich doesn't seems to exist and crash the application. Looks like we will have to use a hardcoded path. ---------------------------------------------------------------------- ludob · 2012-10-02 11:12 QuoteGetAppConfigDir(false) returns '.config/app_process' wich doesn't seems to exist and crash the application.Call ForceDirectories with that dir path to create the directory. IIRC a feature request was made to add ForceDirectories to GetAppConfigDir. ---------------------------------------------------------------------- marcov · 2012-10-02 14:33 Quote from: ludob on October 02, 2012, 01:12:01 pmQuoteGetAppConfigDir(false) returns '.config/app_process' wich doesn't seems to exist and crash the application.Call ForceDirectories with that dir path to create the directory. IIRC a feature request was made to add ForceDirectories to GetAppConfigDir. That's bad, since then it will be created if you only want to check if there is a configuration?