读书人

捕获程序退出错误自动发送邮件

发布时间: 2012-09-03 09:48:39 作者: rapoo

捕获程序退出异常自动发送邮件

在主线程中

class MyUncaughtExceptionHandler implements UncaughtExceptionHandler{private final Context myContext;public MyUncaughtExceptionHandler(Context context){myContext=context;}@Overridepublic void uncaughtException(Thread thread, Throwable ex) {// TODO Auto-generated method stubStringWriter stackTrace=new StringWriter();ex.printStackTrace(new PrintWriter(stackTrace));System.err.println(stackTrace);//Intent sendIntent=new Intent(Intent.ACTION_SEND);sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"5782652@qq.com"});sendIntent.putExtra(Intent.EXTRA_TEXT, stackTrace.toString());sendIntent.putExtra(Intent.EXTRA_SUBJECT,"exception");sendIntent.setType("message/rfc822");myContext.startActivity(sendIntent);android.os.Process.killProcess(android.os.Process.myPid());}}

?

读书人网 >移动开发

热点推荐