How to catch my application's crash report
I am developing android application.开发者_StackOverflow I want to send an email to myself whenever my app crashes on a device, so that I can find my application's crash report through email. How can I implement this concept in my app? Have any exception handler for it?
I am catching un-handled exceptions by using this in my activity's onCreate()
:
mUEHandler = new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
try {
PrintWriter pw = new PrintWriter(new OutputStreamWriter(
openFileOutput(DMP_FILENAME, 0)));
e.printStackTrace(pw);
pw.flush();
pw.close();
} catch (FileNotFoundException e1) {
// do nothing
}
BaseActivity.this.finish();
}
};
Thread.setDefaultUncaughtExceptionHandler(mUEHandler);
This writes every unhandled exception in your app that happened on your activity to text file. Then you can analyze it.
I use ACRA http://code.google.com/p/acra/ to collect crash reports. Since these are collected into Google docs-based spreadsheet you can configure to be notified when that doc is updated
If you add your application to the Android Market, then Google sends crash reports to your e-mail too. Actually Google sends unhandled exceptions that occur in application that leads to crash (force close). No special code is needed for that.
精彩评论