My 6.0.1 app behaves strangely on 2013 nexus (which is not rooted) when power cycles, so I am attempting to write a log file to the internal storage. I have socket logging over the WiFi working to the PC, but the problem occurs when the power is recycled, and my app starts when it receives a boot complete, so I thought I would write a log file, so I am trying:
String filename="tablet.log";
File logFile = new File(getFilesDir(), filename);
p("log file: "+logFile);
try {
OutputStream outputStream = new FileOutputStream(logFile);
outputStream.write("foo\n".getBytes());
outputStream.close();
p("wrote to log file: ");
} catch (Exception e) {
e.printStackTrace();
}
try {
InputStream inputStream = new FileInputStream(logFile);
BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(inputStream));
String string=bufferedReader.readLine();
inputStream.close();
p("read from log file: "+string);
} catch (Exception e) {
e.printStackTrace();
}
Logger global=Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
LoggingHandler.init();
LoggingHandler.setLevel(Level.WARNING);
try {
p("log file get name: "+logFile.getPath());
Handler handler=new FileHandler(logFile.getPath());
handler.setLevel(Level.ALL);
l.addHandler(handler);
l.warning("added file handler: "+handler);
} catch(Exception e) {
l.warning("file handler caught: "+e);
}
I seem to be writing the file and the file handler seems to be added, but I can not see the file when I use adb:
D:\AndroidStudioProjects\Cb7>adb -s 0a9196e8 shell ls /data/user/0/com.tayek.tablet.gui.android.cb7
gets: opendir failed, Permission denied
Is there any way to get the file to the PC?
thanks
edit: jared's suggestion works: adb shell run-as com.tayek.tablet.gui.android.cb7 ls files - will show me the files!
also, adb exec-out run-as package.name cat files/file > file gets the file to the PC.
looks like one needs: adb -s %device% shell run-as %package% ls -l /data/data/%package%/files