简体   繁体   English

如何在设备上访问logcat文件

[英]how can i access logcat file on device

How can I access and read the logcat file (at "/system/bin/logcat") from the device, using my application. 如何使用我的应用程序从设备访问和读取logcat文件(在“/ system / bin / logcat”中)。 My phone is not rooted. 我的手机没有扎根。

Do I need a super user permission? 我需要超级用户权限吗?

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()

Store this bufferedReader in an string or string builder to check your logs 将此bufferedReader存储在字符串或字符串生成器中以检查日志

yes you need permission in your manifest file: 是的,您需要在清单文件中获得权限:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM