Android device's log file
using logcat I can see the log messages generated by my app in the emulator. How can I read/retrieve the same log file but this time from the device the app i开发者_如何学编程s running on ? The device is not attached to any computer and the log file has to be sent via email.
To read the log from within your application you need to have the android.permission.READ_LOGS permission.
Once you have that, you could start up a process to read logcat with something like
Process logcatProcess = Runtime.getRuntime().exec("logcat");
Then you can create a buffered reader from it:
BufferedReader logcat = new BufferedReader(new InputStreamReader(logcatProcess.getInputStream()), 8192);
From here you can String s = logcat.readLine();
to read the log.
There is a log collector project that you can use from your code/application. If you want an already existing application, try Log Collector.
Check out this app on the market. It does what you need and it is open source!
精彩评论