如何在android 7.1的rk3288上设置权限?

时间:2019-04-29 12:58:37

标签: android

环境:rk3288 cpu,android7.1,sftp

我想用android代码在下面做这些事情: 1.使用代码“ adb logcat -d -v time -f /mnt/sdcard/logcat.txt”获取logcat 2.使用sftp将文件logcat.tx拉到服务器上

第一步,我用如下所示的android studio编码一些Java语言,如果有人可以帮助我,谢谢!

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

错误按摩:

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

1 个答案:

答案 0 :(得分:0)

您不能从设备内部使用adb命令,即使您以某种方式在设备中使用它也需要root权限。 adb是PC与设备之间的桥梁。在这里看看:https://developer.android.com/studio/command-line/adb

尽管您可能只需要删除adb并直接使用logcat,例如:

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

在这里,您可以看到更多有关使用logcat命令的选项:Read logcat programmatically within application,包括Reetpreet Brar的答案,我认为这对您会更好:

    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.
    }

您可以在此处选择写入文件的方法:How to Read/Write String from a File in Android

然后,只需将文件发送到服务器即可。