0
down vote favorite 1 share [g+] share [fb] share [tw]

I need the bugreport option that you can use in adb to go to a file on the sd in my app. I foundAndroid; 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();   } 
android adb dump bug-reporting
link | improve this question edited Jan 26 at 5:49 androiddeveloper1162331
17 5
asked Jan 25 at 22:05 user975751
72 6
100% accept rate
feedback

1 Answer

active oldest votes
up vote 1 down vote accepted

I got it working. I foundSOLVED- Running Shell commands though java code on Androidand 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 readingSOLVED- 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();       }

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android(安卓)编解码
  2. Android(安卓)的一些提示框
  3. android studio 将背景设置为黑色或者白
  4. 从网上找的Android实用代码,记录备用
  5. Failed to Sync Gradle, could not find
  6. Android(java)学习笔记63:线程的调度
  7. Android中实现输入图片地址浏览图片操作
  8. android实现高性能,高并发,可延时线程池管
  9. Android利用ViewFlipper实现屏幕切换动画
  10. Android通过Movie展示Gif格式图片