1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
package logcloud.logsintotextfield;
import android.os.AsyncTask;
import android.os.Looper;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ScrollView;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class logsIntoTextfieldMainActivity extends AppCompatActivity {
public EditText logsTextfieldId;
public ScrollView logContainer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity_logs_into_textfield);
logsTextfieldId = (EditText) findViewById(R.id.logsTextfieldId);
logContainer = (ScrollView)findViewById(R.id.logContainer);
getLogs();
}
protected void getLogs() {
GetLogs getLogs = new GetLogs(this);
getLogs.execute();
}
}
class GetLogs extends AsyncTask<Void, String, Void> {
protected logsIntoTextfieldMainActivity context;
public GetLogs(logsIntoTextfieldMainActivity _context){
context = _context;
}
@Override
protected Void doInBackground(Void... voids) {
try {
Process process = Runtime.getRuntime().exec("logcat -v time");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line = "";
while ((line = bufferedReader.readLine()) != null) {
publishProgress(line);
}
}
catch (IOException e) {
}
return null;
}
@Override
protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);
context.logsTextfieldId.append(values[0] + "\n");
context.logContainer.post(new Runnable() {
@Override
public void run() {
context.logContainer.fullScroll(View.FOCUS_DOWN);
}
});
}
} |
Partager