public static void init(Context applicationContext) {
context = applicationContext;
defaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(new CrashHandler());
}
@Override
public void uncaughtException(@NonNull Thread t, @NonNull Throwable e) {
try {
File file = dealException(t, e);
} catch (Exception exception) {
} finally {
if (defaultUncaughtExceptionHandler != null) {
defaultUncaughtExceptionHandler.uncaughtException(t, e);
}
}
}
private File dealException(Thread thread, Throwable throwable) throws JSONException, IOException, PackageManager.NameNotFoundException {
String time = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”).format(new Date());
//私有目录,无需权限
File f = new File(context.getExternalCacheD