public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
//获取未捕获的异常
ex.printStackTrace();
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "errorlog";
File file = new File(path);
try {
PrintWriter printWriter = new PrintWriter(file);
ex.printStackTrace(printWriter);
printWriter.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
System.exit(0);
}
});
}
<application
android:name=".global.MyApplication"
联系客服