0

When I run "adb shell dumpsys wifi" on the android studio terminal I am able to see logs but when I am trying to do it using java and trying to save it in another file it does not work.

With other dumpsys commands such as "dumpsys display", "dumpsys cpuinfo", "dumpsys input " all are working and giving file with logs but not "dumpsys wifi" and giving "Can't find service : wifi" in dumpsy wifi case.

  File storageDir = Environment.getExternalStorageDirectory();
    File outputFile = new File(storageDir, "dumpsys_wifi_log.txt");
    try {
        ProcessBuilder processBuilder = new ProcessBuilder("dumpsys", "wifi");
        processBuilder.redirectErrorStream(true);
        Process process = processBuilder.start();
        process.waitFor();
        StringBuilder stringBuilder = new StringBuilder();
        java.io.InputStream inputStream = process.getInputStream();
        int ch;
        while ((ch = inputStream.read()) != -1) {
            stringBuilder.append((char) ch);
        }
        BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile));
        writer.write(stringBuilder.toString());
        writer.close();
    } catch (IOException | InterruptedException e) {
        e.printStackTrace();
    }
Lino
  • 5,084
  • 3
  • 21
  • 39
NiJ
  • 23
  • 6

0 Answers0