Road to capture android log using java code

In this post I will show you how to capture android log using java code.
public static void captureAndroidDevicesLog() {
  try {
   Process process = Runtime.getRuntime().exec("adb logcat");

   BufferedReader reader = new BufferedReader(new InputStreamReader(
         process.getInputStream()));
   String s;
   System.out.println("*********************************************");
   System.out.println("Printing android logs");
   System.out.println("*********************************************");
   while ((s = reader.readLine()) != null) {
    System.out.println(s);
   }
   System.out.println("*********************************************");
   System.out.println("End printing android logs");
   System.out.println("*********************************************");
  } catch (IOException e) {
   e.printStackTrace();
  } 
}

Above code capture all log of android device and print in console. Yo can manupulate as per you need.

1 comment:

Leave your comments, queries, suggestion I will try to provide solution