首页 > 解决方案 > 如何使用 android 7.1 在 rk3288 上设置权限?

问题描述

环境: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

标签: android

解决方案


您不能从设备内部使用 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

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


推荐阅读