Can logcat results for Log.i be considered in our work?

I want to display the results of Log.i in my application. Is it possible? If so, how can I do this?

+2
source share
1 answer

Here's a blogpost that does exactly what you need for this. It contains a complete code example on how to display the contents of a Logcat log. Here is the code:

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; class ReadLogDemo extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); try { Process process = Runtime.getRuntime().exec("logcat -d"); BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(process.getInputStream())); StringBuilder log=new StringBuilder(); String line = ""; while ((line = bufferedReader.readLine()) != null) { log.append(line); } TextView tv = (TextView)findViewById(R.id.textView1); tv.setText(log.toString()); } catch (IOException e) { } } } 
+9
source

Source: https://habr.com/ru/post/973935/


All Articles