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

Popular posts from this blog

Problems To Upgrade Android Gradle Plugin from 4.1.3 to 8.1.2 and solutions

How to Add Animation to Android App in JAVA

Get Android App Version No and Display in a Text Field