13

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?

Oak Bytes
  • 4,649
  • 4
  • 36
  • 53
user975349
  • 173
  • 2
  • 6

1 Answers1

13

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"/>
Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
Padma Kumar
  • 19,893
  • 17
  • 73
  • 130
  • Is there any way to execute this without creating a different process ? coz this results are not cleared the next time we execute it ... – AbhishekB Aug 28 '12 at 13:01
  • 4
    I don't see how `READ_LOGS` permission is related to launching logcat – basin Apr 22 '14 at 16:57