-1

my environment: cpu:rk3288 os:android7.1 transfer method:sftp

I wrote android code to do these things below:

  1. get the logcat with code "adb logcat -d -v time -f /mnt/sdcard/logcat.txt"
  2. pull the file logcat.tx to the server with sftp

in 1st step I coding some java language with android studio like below, if anyone can help me, thanks!

Process p = Runtime.getRuntime().exec("adb logcat -d -v time -f /mnt/sdcard/logcat.txt");

error massage:

java.io.IOException: Cannot run program "adb": error=13, Permission denied

1 Answers1

0

You can't use adb commands from inside the device, even if you somehow have it in the device you would need root permissions. The adb is the bridge between the PC and the device. Take a look here: https://developer.android.com/studio/command-line/adb

Although you probably can just remove the adb and use logcat directly, like:

Process p = Runtime.getRuntime().exec("logcat -d -v time -f /mnt/sdcard/logcat.txt");

Here you can see some more options about using the logcat command: Read logcat programmatically within application, including Reetpreet Brar's answer, that I think will be better for you:

    Process pq=Runtime.getRuntime().exec("logcat v main"); //adapt the command for yourself
    BufferedReader brq = new BufferedReader(new InputStreamReader(pq.getInputStream()));
    String sq="";
    while ((sq = brq.readLine()) != null)
    {
      //here you can do what you want with the log, like writing in a file to 
      //send to the server later.
    }

Here you can choose methods to write your file: How to Read/Write String from a File in Android

Then, just send the file to the server.

Ricardo A.
  • 685
  • 2
  • 8
  • 35