1

I am trying to write output of atrace to sdcard. I am using getRuntime().exec()("atrace gfx > /storage/sdcard0/trace.txt") in the app.App is signed as a system app and the command is working fine from terminal.But no file is created when running it from the app.

Anonymous
  • 53
  • 1
  • 7
  • Does your app have permission to open a file on external storage? (http://developer.android.com/training/basics/data-storage/files.html) – fadden Mar 11 '15 at 15:53

1 Answers1

1

I solved it by reading data from inputstream and writing it to a file

 try {


                        Process p = Runtime.getRuntime().exec("atrace -t 5 gfx");
                        p.waitFor();
                        BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
                        String line = reader.readLine();
                        File myFile = new File("/storage/sdcard0/trac.txt");
                        FileOutputStream f = null;

                        try {
                            f = new FileOutputStream(myFile);
                        } catch (FileNotFoundException e) {
                            e.printStackTrace();
                        }
                        PrintWriter pw = new PrintWriter(f);
                        while (line != null) {
                            pw.println(line);

                            //Toast.makeText(getBaseContext(), line, Toast.LENGTH_LONG).show();
                            line = reader.readLine();
                        }
                        pw.flush();
                        pw.close();
                        f.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
Anonymous
  • 53
  • 1
  • 7