Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ExceptionHandler.java
- import java.lang.Thread.UncaughtExceptionHandler;
- import android.app.Application;
- import android.app.NotificationManager;
- import android.content.Context;
- import android.os.Process;
- public class ExceptionHandler implements UncaughtExceptionHandler {
- private static Application application = null;
- public ExceptionHandler(Application application) {
- ExceptionHandler.application = application;
- }
- public void uncaughtException(Thread thread, Throwable ex) {
- addBugReport(ex);
- showReportNotification();
- Process.killProcess(Process.myPid());
- }
- private static void addBugReport(Throwable e) {
- // ...
- }
- private void showReportNotification() {
- NotificationManager nm = (NotificationManager) application
- .getSystemService(Context.NOTIFICATION_SERVICE);
- // ...
- }
- }
- // BugReportingApplication.java
- import android.app.Application;
- public class BugReportingApplication extends Application {
- @Override
- public void onCreate() {
- super.onCreate();
- Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));
- }
- }
- // AndroidManifest.xml
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="..."
- android:versionCode="1"
- android:versionName="1.0" >
- <!-- ... -->
- <application
- android:name="BugReportingApplication"
- android:icon="@drawable/logo"
- android:label="@string/app_name" >
- <!-- ... -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement