I'm pretty new to Android development. I want to develop an App, that is able to save a text file on the internal storage (in the App's private folder or something like that).
I have following code:
procedure TfrmMain.Button1Click(Sender: TObject);
var
tstrTmp: TStringList;
sFn: String;
begin
tstrTmp := TStringList.Create;
tstrTmp.Text := 'Test';
sFn := Format( '%s/Test.txt', [GetHomePath ]);
sFn := System.IOUtils.TPath.GetDocumentsPath + System.SysUtils.PathDelim + 'Test.txt';
sFn := TPath.Combine( System.IOUtils.TPath.GetDocumentsPath , 'Test.txt' );
tstrTmp.SaveToFile( sFn );
tstrTmp.Free;
showmessage( sFn );
end;
When I run the App and click the button, it is showing me: '/data/user/0/com.embarcadero.[MyAppName]/files/Test.txt'. So, I would assume that the file was physically written to that location.
But when I connect my device to my pc, I can't even find this folder. I also searched on the external storage but I was not able to find this folder or file (Test.txt).
I did found a folder on my internal storage : /Android/data/com.embarcadero.[MyAppName]/files, but no file in there.
so, I'm a bit stuck here, because I would assume the file is saved somewhere. But I'm not able to find it.
Am I doing something wrong here? Thanks for your feedback.
Best Regards,
Wim.
GetHomePath/TPath.GetDocumentsPathis private to your app, it is not exposed to other apps or the PC. If you want to make a file accessible to them, it needs to be created in a public folder instead, likeTPath.GetSharedDocumentsPath. Also, just FYI, last time I checked (albeit that was a long while ago), FireMonkey did a pretty lousy job of reporting errors for various operations, like creating files, so more times than not you wouldn't know if such operations actually succeeded or failed.