How to get a run-time log when the power of closing an Android application

How to get a log at runtime when the power closes in the Android app. I want to receive the magazines and mail them.

+4
source share
3 answers

Here is some code for collecting logs inside the application:

private int MAX_LOG_MESSAGE_LENGTH = 100000; private String[] mFilterSpecs; private String mFormat; private String mBuffer; private class CollectLogTask extends AsyncTask<ArrayList<String>, Void, StringBuilder> { @Override protected void onPreExecute() { } @Override protected StringBuilder doInBackground(ArrayList<String>... params) { final StringBuilder log = new StringBuilder(); try { ArrayList<String> commandLine = new ArrayList<String>(); commandLine.add("logcat");//$NON-NLS-1$ commandLine.add("-d");//$NON-NLS-1$ ArrayList<String> arguments = ((params != null) && (params.length > 0)) ? params[0] : null; if (null != arguments) { commandLine.addAll(arguments); } Process process = Runtime.getRuntime().exec(commandLine.toArray(new String[0])); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while ((line = bufferedReader.readLine()) != null) { log.append(line); log.append(LINE_SEPARATOR); } } catch (IOException e) { Log.e(TAG, "CollectLogTask.doInBackground failed", e);//$NON-NLS-1$ } return log; } @Override protected void onPostExecute(final StringBuilder log) { if (null != log) { // truncate if necessary int keepOffset = Math.max(log.length() - MAX_LOG_MESSAGE_LENGTH, 0); if (keepOffset > 0) { log.delete(0, keepOffset); } if (mAdditonalInfo != null) { log.insert(0, LINE_SEPARATOR); log.insert(0, mAdditonalInfo); } Log.d("printLog",log.toString()); } } } 

Now call this async class as follows.

  ArrayList<String> list = new ArrayList<String>(); if (mFormat != null) { list.add("-v"); list.add(mFormat); } if (mBuffer != null) { list.add("-b"); list.add(mBuffer); } if (mFilterSpecs != null) { for (String filterSpec : mFilterSpecs) { list.add(filterSpec); } } new CollectLogTask().execute(list); 
+3
source

Use ACRA or related libraries to break production application crashes and process these reports. By default, ACRA will write material to the Google Docs spreadsheet, but you can replace it with something else.

+2
source

adb logcat when the device is connected to USB debugging

or

install aLogCat from gplay.

+1
source

All Articles