0

I am developing Android app and i want to have log file. I am able to create log file on the emulator and see it but when I ran the application on the device the log file is not generated. not only that, the directory with package name is not created under the /data/data/.

FileOutputStream   loggerFile; 
OutputStreamWriter LOGGER; 
Calendar c ;
private static String LOG_FILE_NAME = "QuickPark.log";
loggerFile = openFileOutput(LOG_FILE_NAME,
                MODE_APPEND);           
        LOGGER = new OutputStreamWriter(loggerFile);

        LOGGER.write("Application started to run on " + c.get(Calendar.DATE) + " -- " + c.get(Calendar.HOUR_OF_DAY));

More clarifications: I ran this code on the device, connected to it and did not see the dir with package name.

please help me understand what i am missing.

Thanks, Dudy.

  • you have to write your file on `external storage` – rajpara Jul 23 '12 at 13:59
  • You don't have to write the file on external storage, but it will be easier if you do. If not, you have to use the run-as command if the apk is debuggable, or else you have to make the file (and perhaps its containing directory) world readable and go directly to it's directory, since you cannot list /data and it's immediate subfolders from adb's *shell* userid. On the emulator, adb gives you root which is a pass through all that. – Chris Stratton Jul 23 '12 at 14:03

1 Answers1

0

As far as I know you usually don't have permission to access /data/data on an android device, only if it is rooted

You will have to write some code in your app to access/copy the file, here is an example where this is done with a sqlite db

DDMS file explorer can't access data\data (HTC Desire HD)

Or put the Logfile on the SDCard in the first place

Community
  • 1
  • 1
Hans Hohenfeld
  • 1,729
  • 11
  • 14