首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

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

2012-09-03 
捕获程序退出异常自动发送邮件在主线程中class MyUncaughtExceptionHandler implements UncaughtException

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

在主线程中

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());}}

?

热点排行