Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android LogCat编程-所有进程_Android_Logcat - Fatal编程技术网

Android LogCat编程-所有进程

Android LogCat编程-所有进程,android,logcat,Android,Logcat,是否可以读取所有进程的LogCat消息?(就像在android studio中,当我们选择“无过滤器”选项时) 当我执行此命令时: File filename = new File(Environment.getExternalStorageDirectory() + "/mylog.txt"); if (filename.exists()) { filename.delete(); } String cmd = "logcat -f " + f

是否可以读取所有进程的LogCat消息?(就像在android studio中,当我们选择“无过滤器”选项时)

当我执行此命令时:

    File filename = new File(Environment.getExternalStorageDirectory() + "/mylog.txt");
    if (filename.exists()) {
        filename.delete();
    }

    String cmd = "logcat -f " + filename.getAbsolutePath();
    Runtime.getRuntime().exec(cmd);

它只写连接到我的应用程序的日志。

从android 4.1+版开始,你不能再读取其他应用程序的日志。请参阅以供参考

读取版本低于4.1的其他应用程序的日志

Runtime.getRuntime().exec("logcat -c").waitFor();
Process process = Runtime.getRuntime().exec("logcat -v long *:*");
BufferedReader reader = 
new BufferedReader(new InputStreamReader(process.getInputStream()));
while (true) {
    String nextLine = reader.readLine();
    if (!nextLine.contains("LogWatcher-D")) {
        Log.w("LogWatcher-D", "See: " + nextLine);
    }
}
您需要授予
权限

要想弄清楚,你可以参考