我怎么可以访问设备logcat的文件我怎么、文件、设备、logcat

2023-09-12 08:09:53 作者:袭人

我怎样才能从设备访问和读取的logcat文件(在/系统/斌/的logcat),用我的应用程序。我的手机是不是植根。

How can I access and read the logcat file (at "/system/bin/logcat") from the device, using my application. My phone is not rooted.

我需要超级用户权限?

推荐答案

您可以通过这个code从应用程序中读取

you can read through this code from your application

ArrayList<String> commandLine = new ArrayList<String>();
commandLine.add("logcat"); //$NON-NLS-1$
commandLine.add("-d"); //$NON-NLS-1$
ArrayList<String> arguments =
    ((params != null) && (params.length > 0)) ? params[0] : null;
if (null != arguments) {
    commandLine.addAll(arguments);
}

Process process = Runtime.getRuntime().exec(commandLine.toArray(new String[0]));
BufferedReader bufferedReader = new BufferedReader(
    new InputStreamReader(process.getInputStream()), 1024);

bufferedReader.readLine()

店铺的BufferedReader在字符串或字符串生成器来检查你的日志

Store this bufferedReader in an string or string builder to check your logs

是的,你需要在你的清单文件权限:

yes you need permission in your manifest file:

<uses-permission android:name="android.permission.READ_LOGS"/>