文件
package com.example.mobilesafe.app;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.lang.Thread.UncaughtExceptionHandler;
import android.app.Application;
import android.os.Environment;
public class myApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
ex.printStackTrace();
String path = Environment.getExternalStorageDirectory()
.getAbsoluteFile() + File.separator + "error.log";
File file = new File(path);
try {
PrintWriter printWriter = new PrintWriter(file);
ex.printStackTrace(printWriter);
printWriter.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.exit(0);
}
});
}
}
在配置文件中配置
<application
android:name=".myApplication "