Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i access logcat file on device

How can I access and read the logcat file (at "/system/bin/logcat") from the device, using my application. My phone is not rooted.

Do I need a super user permission?

like image 517
user975349 Avatar asked Dec 07 '11 14:12

user975349


People also ask

Where are Logcat files stored?

They are stored as circular memory buffers on the device. If you run "adb logcat > myfile" on your host system, you can retrieve the content into a file.


1 Answers

you can read through this code from your application

ArrayList<String> commandLine = new ArrayList<String>();
commandLine.add("logcat"); //$NON-NLS-1$
commandLine.add("-d"); //$NON-NLS-1$
ArrayList<String> arguments =
    ((params != null) && (params.length > 0)) ? params[0] : null;
if (null != arguments) {
    commandLine.addAll(arguments);
}

Process process = Runtime.getRuntime().exec(commandLine.toArray(new String[0]));
BufferedReader bufferedReader = new BufferedReader(
    new InputStreamReader(process.getInputStream()), 1024);

bufferedReader.readLine()

Store this bufferedReader in an string or string builder to check your logs

yes you need permission in your manifest file:

<uses-permission android:name="android.permission.READ_LOGS"/>
like image 101
Padma Kumar Avatar answered Oct 24 '22 21:10

Padma Kumar