将dumpstate写入文件android

Jas*_*s10 2 android dump bug-reporting adb

我需要你可以在adb中使用的bugreport选项转到我的应用程序中的sd上的文件.我找到了Android; 使用exec("bugreport")解释你不能在常规shell中运行bugreport,并且你需要分别运行dumpstate,dumpsys和logcat以获得相同的结果.这很好,我理解,但我不能让dumpstate或dumpsys写入文件.以下工作正常使用logcat -d -f编写logcat,但不适用于其他两个.我已经尝试了dumpstate -f,dumpstate -d -f和dumpstate>来使它工作,但仍然没有写任何文件.是否有一些我缺少的东西使这项工作?
这是我在sd上创建文件的地方

File folder = new File(Environment.getExternalStorageDirectory()+"/IssueReport/");
    if (folder.isDirectory() == false) {
        folder.mkdir();
    }
    log = new File(Environment.getExternalStorageDirectory()+"/IssueReport/log.txt");
Run Code Online (Sandbox Code Playgroud)

这是我将文件写入该位置的位置

private void submit() {
    try {
       log.createNewFile(); 
       String cmd = "dumpstate "+log.getAbsolutePath();
       Runtime.getRuntime().exec(cmd);
    } catch (IOException e) {
    e.printStackTrace();
    }
Run Code Online (Sandbox Code Playgroud)

Jas*_*s10 8

我搞定了.我通过Android上的java代码找到了Running Shell命令?并将其修改为像我需要的那样工作.

private void submit() {
    try {
         String[] commands = {"dumpstate > /sdcard/log1.txt"};
         Process p = Runtime.getRuntime().exec("/system/bin/sh -");
         DataOutputStream os = new DataOutputStream(p.getOutputStream());
            for (String tmpCmd : commands) {
                os.writeBytes(tmpCmd+"\n");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
Run Code Online (Sandbox Code Playgroud)

如果有人需要它,这就是我一起运行所有东西的方式.应用程序需要附加一个错误报告,通过Android上的Java代码读取Running Shell命令?,我看到没有办法运行错误报告,只有三个组件:dumpstate,dumpsys和log.我将单独生成每个报告,然后将它们全部合并到一个文件中以附加到电子邮件中.

private void submit() {
    try {
         String[] commands = {"dumpstate > /sdcard/IssueReport/dumpstate.txt", 
                              "dumpsys > /sdcard/IssueReport/dumpsys.txt",
                              "logcat -d > /sdcard/IssueReport/log.txt",
                              "cat /sdcard/IssueReport/dumpstate.txt /sdcard/IssueReport/dumpsys.txt /sdcard/IssueReport/log.txt > /sdcard/IssueReport/bugreport.rtf" };
         Process p = Runtime.getRuntime().exec("/system/bin/sh -");
         DataOutputStream os = new DataOutputStream(p.getOutputStream());
            for (String tmpCmd : commands) {
                    os.writeBytes(tmpCmd+"\n");
            }
        } catch (IOException e) {
            e.printStackTrace();    
        }
Run Code Online (Sandbox Code Playgroud)