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.
So, the solution was: Set the App-Permisisons for Storage (Settings - Apps - MyApp - Permission - Storage).
Once this was done, using the TPath.GetPublicPath to store the file resulted in a file on the Device (Internal Storage) on: /storage/emulated/0/Android/data//files Where '/storage/emulated/0' = the rootfolder of the internal storage of my device.