Created
January 30, 2015 07:26
-
-
Save natuanorg/db0e78f1607c98aac3d3 to your computer and use it in GitHub Desktop.
ExceptionHandler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ExceptionHandler implements | |
java.lang.Thread.UncaughtExceptionHandler { | |
private final Activity myContext; | |
private final String LINE_SEPARATOR = "\n"; | |
private final String TAG = "ExceptionHandler"; | |
public ExceptionHandler(Activity context) { | |
myContext = context; | |
} | |
public void uncaughtException(Thread thread, Throwable exception) { | |
StringWriter stackTrace = new StringWriter(); | |
exception.printStackTrace(new PrintWriter(stackTrace)); | |
StringBuilder errorReport = new StringBuilder(); | |
errorReport.append("************ CAUSE OF ERROR ************\n\n"); | |
errorReport.append(stackTrace.toString()); | |
errorReport.append("\n************ DEVICE INFORMATION ***********\n"); | |
errorReport.append("Brand: "); | |
errorReport.append(Build.BRAND); | |
errorReport.append(LINE_SEPARATOR); | |
errorReport.append("Device: "); | |
errorReport.append(Build.DEVICE); | |
errorReport.append(LINE_SEPARATOR); | |
errorReport.append("Model: "); | |
errorReport.append(Build.MODEL); | |
errorReport.append(LINE_SEPARATOR); | |
errorReport.append("Id: "); | |
errorReport.append(Build.ID); | |
errorReport.append(LINE_SEPARATOR); | |
errorReport.append("Product: "); | |
errorReport.append(Build.PRODUCT); | |
errorReport.append(LINE_SEPARATOR); | |
errorReport.append("\n************ FIRMWARE ************\n"); | |
errorReport.append("SDK: "); | |
errorReport.append(Build.VERSION.SDK); | |
errorReport.append(LINE_SEPARATOR); | |
errorReport.append("Release: "); | |
errorReport.append(Build.VERSION.RELEASE); | |
errorReport.append(LINE_SEPARATOR); | |
errorReport.append("Incremental: "); | |
errorReport.append(Build.VERSION.INCREMENTAL); | |
errorReport.append(LINE_SEPARATOR); | |
Log.d(TAG, errorReport.toString()); | |
Intent intent = new Intent(myContext, SplashActivity.class); | |
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); | |
myContext.startActivity(intent); | |
android.os.Process.killProcess(android.os.Process.myPid()); | |
System.exit(10); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment