|
| 1 | +package com.aidlux.usbcamera; |
| 2 | + |
| 3 | +import android.content.Context; |
| 4 | +import android.os.Environment; |
| 5 | +import android.util.Log; |
| 6 | + |
| 7 | +import org.acra.ReportField; |
| 8 | +import org.acra.data.CrashReportData; |
| 9 | +import org.acra.sender.ReportSender; |
| 10 | +import org.acra.sender.ReportSenderException; |
| 11 | + |
| 12 | +import java.io.File; |
| 13 | +import java.io.FileNotFoundException; |
| 14 | +import java.io.FileOutputStream; |
| 15 | +import java.io.IOException; |
| 16 | +import java.io.OutputStreamWriter; |
| 17 | + |
| 18 | +public class AcraFileSender implements ReportSender { |
| 19 | + @Override |
| 20 | + public void send(Context context, CrashReportData report) throws ReportSenderException { |
| 21 | + String error_log = ""; |
| 22 | + error_log += report.getString(ReportField.LOGCAT); |
| 23 | +// final String storagePath = context.getExternalFilesDir(null).getAbsolutePath() + File.separator + "USBCamera"; |
| 24 | + final String storagePath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "USBCamera"; |
| 25 | + final String crashFileName = "CrashReport.txt"; |
| 26 | + final File storageDir = new File(storagePath); |
| 27 | + if (!storageDir.exists()) { |
| 28 | + storageDir.mkdir(); |
| 29 | + } |
| 30 | + String crashFilePath = storagePath + File.separator + crashFileName; |
| 31 | + |
| 32 | + try { |
| 33 | + File file = new File(crashFilePath); |
| 34 | + FileOutputStream out = new FileOutputStream(file); |
| 35 | + OutputStreamWriter writer = new OutputStreamWriter(out); |
| 36 | + |
| 37 | + writer.append(error_log); |
| 38 | + writer.close(); |
| 39 | + |
| 40 | + out.flush(); |
| 41 | + out.close(); |
| 42 | + |
| 43 | + Log.i("Acra", "Crash log saved."); |
| 44 | + } catch (FileNotFoundException e) { |
| 45 | + e.printStackTrace(); |
| 46 | + } catch (IOException e) { |
| 47 | + e.printStackTrace(); |
| 48 | + } |
| 49 | + } |
| 50 | +} |
0 commit comments