Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to send email from Uncaught Excepetion Handler?
    primarykey
    data
    text
    <p>I am implementing Uncaught Exception Handler for trace my app's crash report and send mail to me.But i can't send mail form my exception handler.my Uncaught Exception Handler name is TopExceptionHandler.I am using this code in TopExceptionHandler.java</p> <pre><code>public class TopExceptionHandler implements Thread.UncaughtExceptionHandler { private Thread.UncaughtExceptionHandler defaultUEH; private Activity app = null; public TopExceptionHandler(Activity app) { this.defaultUEH = Thread.getDefaultUncaughtExceptionHandler(); this.app = app; } @Override public void uncaughtException(Thread t, Throwable e) { StackTraceElement[] arr = e.getStackTrace(); String report = e.toString()+"\n\n"; report += "--------- Stack trace ---------\n\n"; for (int i=0; i&lt;arr.length; i++) { report += " "+arr[i].toString()+"\n"; } report += "-------------------------------\n\n"; // If the exception was thrown in a background thread inside // AsyncTask, then the actual exception can be found with getCause report += "--------- Cause ---------\n\n"; Throwable cause = e.getCause(); if(cause != null) { report += cause.toString() + "\n\n"; arr = cause.getStackTrace(); for (int i=0; i&lt;arr.length; i++) { report += " "+arr[i].toString()+"\n"; } } report += "-------------------------------\n\n"; Log.v("report", report); try { FileOutputStream trace = app.openFileOutput( "stack.trace", Context.MODE_PRIVATE); trace.write(report.getBytes()); trace.close(); } catch(IOException ioe) { // ... } sendEmail(report); defaultUEH.uncaughtException(t, e); } private void sendEmail(String report) { try{ Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); String subject = "Error report"; String body = "Mail this to sivaraj@onederr.com: "+ "\n\n"+ report+ "\n\n"; sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {"sivaraj@onederr.com"}); sendIntent.putExtra(Intent.EXTRA_TEXT, report); sendIntent.putExtra(Intent.EXTRA_SUBJECT, "hai"); sendIntent.setType("message/rfc822"); app.startActivity(Intent.createChooser(sendIntent, "Email:")); } catch(Exception e) { Log.v("sendmail", e.toString()); } } @Override protected void finalize() throws Throwable { if (Thread.getDefaultUncaughtExceptionHandler().equals(this)) Thread.setDefaultUncaughtExceptionHandler(defaultUEH); super.finalize(); } </code></pre> <p>}</p> <p>CrashreportActivity.java</p> <pre><code>public class CrashreportActivity extends Activity { protected TopExceptionHandler mDamageReport = new TopExceptionHandler(this); String len=null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Thread.setDefaultUncaughtExceptionHandler(new TopExceptionHandler(this)); for(int i=0;i&lt;len.length();i++) { Log.v("error", ""+i); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload