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. 《算法导论的Java实现》 10 中位数和顺序
  2. Java并发面试题:三个线程轮流打印十次abc
  3. 使用Maven时,不要将JAR添加到Google Cloud
  4. Xstream把xml转换成java对象的异常:java.l
  5. RxJava学习模块之Schduler
  6. JAVA面向对象基础
  7. JAVA生成带LOGO的二维码
  8. Java 编程下的同步代码块(售票员)
  9. 如何指定休眠连接映射?
  10. 在扑克游戏中显示卡片的图像