add crash handling dialog with optional sending of the crash to the author
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / activity / CrashReportingActivity.java
1 package net.ktnx.mobileledger.ui.activity;
2
3 import android.os.Bundle;
4 import android.support.annotation.Nullable;
5 import android.support.v7.app.AppCompatActivity;
6 import android.util.Log;
7
8 import net.ktnx.mobileledger.ui.CrashReportDialogFragment;
9
10 import java.io.PrintWriter;
11 import java.io.StringWriter;
12
13 public class CrashReportingActivity extends AppCompatActivity {
14     @Override
15     protected void onCreate(@Nullable Bundle savedInstanceState) {
16         super.onCreate(savedInstanceState);
17
18         Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
19             @Override
20             public void uncaughtException(Thread t, Throwable e) {
21                 StringWriter sw = new StringWriter();
22                 PrintWriter pw = new PrintWriter(sw);
23                 e.printStackTrace(pw);
24
25                 Log.e(null, sw.toString());
26
27                 CrashReportDialogFragment df = new CrashReportDialogFragment();
28                 df.setCrashReportText(sw.toString());
29                 df.show(getSupportFragmentManager(), "crash_report");
30             }
31         });
32         Log.d("crash", "Uncaught exception handler set");
33     }
34 }