0

I have an App that uses various System.out.println("Bla bla");and I want that all these calls are captured and processed as String so I can view them in a TextView with something like

void updateTextView(String capturedPrintline){
     mytextView.setText(capturedPrintline.processPrint());
}

But unfortunately I don't know how capture ALL System.out.println without editing manually every method class to return the content of the print as String.

How could I achieve my goal?

NB

I need that app shows the System.out.println in the TextView itself also when runs in a device without any external debugger

AndreaF
  • 11,975
  • 27
  • 102
  • 168

1 Answers1

0

You can set your own PrintStream that captures all output using this method:

System.setOut(PrintStream)

tiguchi
  • 5,392
  • 1
  • 33
  • 39
  • Thanks for the answer. Could you give me some sample? – AndreaF Oct 25 '13 at 15:00
  • @AndreaF A PrintStream sends its formatted output to an OutputStream. You can easily create your own OutputStream that implements the methods OutputStream.write(byte[],int,int) and OutputStream.write(int). Let these write methods append the added bytes to your TextView's text. – tiguchi Oct 25 '13 at 18:16