writing dumpstate to file android
来源:互联网 发布:民生证券软件下载 编辑:程序博客网 时间:2024/05/16 04:21
0down votefavorite
I need the bugreport option that you can use in adb to go to a file on the sd in my app. I found Android; using exec("bugreport") that explains that you can not run bugreport in the regular shell and that you need to run dumpstate, dumpsys, and logcat separately to get the same result. That is fine and I understand that, but I can not get dumpstate or dumpsys to write to the file. The below works fine to write the logcat using logcat -d -f, but does not work for the other two. I have tried dumpstate -f , dumpstate -d -f and dumpstate > to get it work, but still does not write anything to the file. Is there something I am missing to make this work?
This is where I am creating the file on the sd
File folder = new File(Environment.getExternalStorageDirectory()+"/IssueReport/"); if (folder.isDirectory() == false) { folder.mkdir(); } log = new File(Environment.getExternalStorageDirectory()+"/IssueReport/log.txt");
and here is where I am writing the file to the location
private void submit() { try { log.createNewFile(); String cmd = "dumpstate "+log.getAbsolutePath(); Runtime.getRuntime().exec(cmd); } catch (IOException e) { e.printStackTrace(); }
1 Answer
I got it working. I found SOLVED- Running Shell commands though java code on Android and modified it to work like I needed it to.
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(); }
If anyone needs it, here is the way I am running everything together. The app needs to have a bug report attached to it, from reading SOLVED- Running Shell commands though java code on Android , I saw that there is not a way to run a bug report, just the three componenets: dumpstate, dumpsys, and log. I am generating each report separately and then combining them all into one file to attach to an email.
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(); }
- writing dumpstate to file android
- Writing to a Temporary File
- Writing to a Binary File
- Android dumpstate 工具解析
- Android dumpstate 工具解析
- Android dumpstate 工具解析
- Android之dumpstate
- Android dumpstate 工具解析
- Android dumpstate 工具解析
- Android dumpstate 工具解析
- Writing a DIB to a JPEG file
- Writing a bitmap to a BMP file
- error writing to lock file 郁闷
- //outfile.cpp--writing to a file
- PHP Reading A File |and| Writing To A File
- Code: Writing Text to a File (Visual Basic)
- EXP-00002: error in writing to export file
- exp error EXP-00002: error in writing to export file
- java-J2SE学习笔记(十三)
- Extjs分页查询出错,查询出来显示时的条数不对
- C++11 FAQ中文版:weak_ptr
- 共享相关问题
- 在Windows平台上安装Node.js及NPM模块管理
- writing dumpstate to file android
- HTTP Header 详解
- erl_crash.dump 的查看
- SQLite—参数绑定和重执行已编译语句
- 本地通知。
- jQuery设置 select、radio、checkbox 默认选中的值
- 在外面打工的人很可怜
- Android 中Odex文件生成与合并, 移植apk【转载+修正】
- IOS学习六:Date Picker, Picker View选取器控件初步