I think the answer from @ Gomoku7 contains some legacy code, so I will just post the solution I used:
Call this in onCreate ():
ACRA.init(this); ACRA.getErrorReporter().setReportSender(new LocalReportSender(this));
Here I basically changed the code to use BufferedWriter so that I could write directly to the SD card, which was not possible with openFileOutput()
. Therefore, only the send()
method and the LocalReportSender()
constructor LocalReportSender()
slightly modified.
Note. Keep in mind that the log file is growing quite fast, so be sure to take the MBs of your user's SD card space because of the log file :)
private class LocalReportSender implements ReportSender { private final Map<ReportField, String> mMapping = new HashMap<ReportField, String>(); private FileWriter crashReport = null; public LocalReportSender(Context ctx) { // the destination File logFile = new File(Environment.getExternalStorageDirectory(), "log.txt"); try { crashReport = new FileWriter(logFile, true); } catch (IOException e) { e.printStackTrace(); } } @Override public void send(CrashReportData report) throws ReportSenderException { final Map<String, String> finalReport = remap(report); try { BufferedWriter buf = new BufferedWriter(crashReport); Set<Entry<String, String>> set = finalReport.entrySet(); Iterator<Entry<String, String>> i = set.iterator(); while (i.hasNext()) { Map.Entry<String, String> me = (Entry<String, String>) i.next(); buf.append("[" + me.getKey() + "]=" + me.getValue()); } buf.flush(); buf.close(); } catch (IOException e) { Log.e("TAG", "IO ERROR", e); } } private boolean isNull(String aString) { return aString == null || ACRAConstants.NULL_VALUE.equals(aString); } private Map<String, String> remap(Map<ReportField, String> report) { ReportField[] fields = ACRA.getConfig().customReportContent(); if (fields.length == 0) { fields = ACRAConstants.DEFAULT_REPORT_FIELDS; } final Map<String, String> finalReport = new HashMap<String, String>( report.size()); for (ReportField field : fields) { if (mMapping == null || mMapping.get(field) == null) { finalReport.put(field.toString(), report.get(field)); } else { finalReport.put(mMapping.get(field), report.get(field)); } } return finalReport; } }
user2302510
source share