how can i access logcat file on device

孤者浪人 提交于 2019-12-28 04:23:12

问题


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?


回答1:


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

yes you need permission in your manifest file:

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


来源:https://stackoverflow.com/questions/8417389/how-can-i-access-logcat-file-on-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!