Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Can't find file written in TPath.GetHomePath on Android device


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Dec 10, 2014 7:17 PM Last Post By: Brian Hamilton ...
Pierre-François...

Posts: 13
Registered: 10/26/12
Can't find file written in TPath.GetHomePath on Android device  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 10, 2014 3:29 PM
My Delphi XE7 Android App succesfully writes log debug info in a Log file opened in System.IOUtils.TPath.GetHomePath (which returns '/data/data/com.embarcadero.MyAppName/files').

The following code is used to assign the file variable:

var 
  FLogFile: text;
  FileName: string;
 
FileName := System.IOUtils.TPath.GetHomePath + System.SysUtils.PathDelim + 'LogFile.txt';
AssignFile(FLogFile, FileName);


The file was created with

Rewrite(FLogFile);


And then opened for later write access with

Append(FLogFile);


It is written with log info messages with that kind of code:

var
  LogMsg: string;
 
Writeln (FLogFile, LogMsg);


And finally closed with:

CloseFile(FLogMsg);


I know the LogFile.txt file was correctly created written and closed, and that it still exists because the application is able to open and read it at each startup with this kind of code:

Reset(FLogFile);
try
  while not eof(FLogFile) do begin
    readln(FLogFile,Line);
  end;
finally
  Close(FLogFile);
end;


I can display the content of each read line from the debugger.

The problem is that I cannot find the log file 'Logfile.txt' on my device from the connected PC in the folder called "internal storage/Android/data/com.embarcadero/MyAppName/file" !!!

This folder exists but appears empty !!!

From the Android device itself as well, I can visit this folder using the Android file explorer app.
In 'My Storage' I find an 'Android' folder, containing a 'data' subfolder with an 'com.embacadero.MyAppName' subfolder in which I find a 'files' subfolder, but this subfolders also appears empty !!!

So where is located the LogFile.txt file I've created from my app ?!?! How to access it from the PC ??? I didn't set any hidden attribute when I created it !

Note that the first level folder is called 'Android' when I browse my internal storage and is called 'data' in the path returned by TPath.GetHomePath. But I think this is right.

Thanks for your help.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Can't find file written in TPath.GetHomePath on Android device  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 10, 2014 4:04 PM   in response to: Pierre-François... in response to: Pierre-François...
Pierre-François wrote:

FileName := System.IOUtils.TPath.GetHomePath + System.SysUtils.PathDelim
+ 'LogFile.txt';

Consider using TPath.Combine() instead:

FileName := TPath.Combine(TPath.GetHomePath, 'LogFile.txt');


AssignFile(FLogFile, FileName);

Why are you using old-style Pascal I/O, instead of something more modern,
like TStreamWriter?

The problem is that I cannot find the log file 'Logfile.txt' on my
device from the connected PC in the folder called "internal
storage/Android/data/com.embarcadero/MyAppName/file" !!!

That is because you don't have access to it. /data/data/ is private to your
app, so only your app can access it. Other apps don't have permission to
it (unless you root your device and grant permission). This is documented
behavior:

Using the Internal Storage
http://developer.android.com/guide/topics/data/data-storage.html#filesInternal

You can save files directly on the device's internal storage. **By default,
files saved to the internal storage are private to your application and other
applications cannot access them (nor can the user)**. When the user uninstalls
your application, these files are removed.

Also see:

How to Find my App's /data/data using Android Device Monitor's File Explorer
http://stackoverflow.com/questions/25616985/

From the Android device itself as well, I can visit this folder using
the Android file explorer app. In 'My Storage' I find an 'Android'
folder, containing a 'data' subfolder with an
'com.embacadero.MyAppName' subfolder in which I find a 'files'
subfolder, but this subfolders also appears empty !!!

The File Explorer is an app, and it does not have access to another app's
private files.

--
Remy Lebeau (TeamB)
Brian Hamilton ...

Posts: 556
Registered: 10/14/04
Re: Can't find file written in TPath.GetHomePath on Android device  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 10, 2014 7:08 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
what are the disadvantages of using the older pascal I/O for text files?
(just interested :) )

Edited by: Brian Hamilton on Dec 10, 2014 7:16 PM
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02