How to Send Crash Report to Email / Mobile Device in Android Java
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable throwable) {
// Handle uncaught exception
sendCrashReport(throwable);
}
});
private void sendCrashReport(Throwable throwable) {
// Collect crash information
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
throwable.printStackTrace(pw);
String crashReport = sw.toString();
// Compose email
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("message/rfc822");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"sidbehala@gmail.com"});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Crash Report");
emailIntent.putExtra(Intent.EXTRA_TEXT, crashReport);
// Launch email intent
startActivity(Intent.createChooser(emailIntent, "Send crash report via..."));
// Exit the app (optional)
System.exit(1);
}
Comments
Post a Comment