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

Error : One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts

HOW TO DISCARD UNDER REVIEW APP BUNDLE AND UPLOAD NEW APP BUNDLE

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