android - 如何使用 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
解决方案
您不能从设备内部使用 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
然后,只需将文件发送到服务器。
推荐阅读
- php - 如何创建两个同名文件夹,如何删除?
- c - 简单的 C 代码不会向终端打印任何内容
- java - 如何修改所有 ProgressBar?
- python - 函数卡在 readlines 中
- mysql - MYSQL 不允许 JSON 数据类型
- r - 在 R 中将 for 循环重写为 lapply 函数
- php - 无法在codeigniter“slug”上加载特定页面
- neural-network - DeepLearning4J - 获取数据和训练模型
- javascript - Angular 从 API 调用返回数据作为 [Object Object],但在组件中未定义
- c - 未在 c 中显示结构数组的正确值