csh_34 2013-01-10 07:55 采纳率: 0%
浏览 2713
已采纳

如何访问移动设备上的logcat文件

使用程序如何在移动设备上如何访问和读取 "/system/bin/logcat"中的logcat文件?

我的手机没有获得root权限。

我需要设置一个超级用户访问权限吗?

  • 写回答

3条回答

  • Curie-87 2013-01-14 03:31
    关注

    你可以从你的应用程序中阅读这段代码

    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,检查logs。
    在manifest文件中添加许可:

    <uses-permission android:name="android.permission.READ_LOGS"/>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?