我如何访问设备上的 logcat 文件 [英] how can i access logcat file on device
本文介绍了我如何访问设备上的 logcat 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用我的应用程序从设备访问和读取 logcat 文件(位于/system/bin/logcat").我的手机没有root.
How can I access and read the logcat file (at "/system/bin/logcat") from the device, using my application. 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()
将此 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"/>
这篇关于我如何访问设备上的 logcat 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文