package com.basic.security.base;
|
|
import android.content.Context;
|
|
import java.io.PrintWriter;
|
import java.io.StringWriter;
|
import java.util.Map;
|
|
public class CrashHandler implements Thread.UncaughtExceptionHandler {
|
static CrashHandler mCrashHandler = null;
|
|
public static CrashHandler getCrashHandler() {
|
if (mCrashHandler == null) {
|
synchronized (CrashHandler.class) {
|
if (mCrashHandler == null) {
|
mCrashHandler = new CrashHandler();
|
}
|
}
|
}
|
return mCrashHandler;
|
}
|
|
@Override
|
public void uncaughtException(Thread t, Throwable e) {
|
handleException(e);
|
}
|
|
public void init(Context context) {
|
Thread.setDefaultUncaughtExceptionHandler(mCrashHandler);
|
}
|
|
private void handleException(Throwable ex) {
|
ex.printStackTrace();
|
BaseApplication application = BaseApplication.getApplication();
|
StringBuilder stringBuilder = new StringBuilder();
|
for (Map.Entry<String, String> entry : application.devInfo.entrySet()) {
|
stringBuilder.append(entry.getKey()).append("=").append(entry.getValue()).append("\n");
|
}
|
PrintWriter printWriter = new PrintWriter(new StringWriter());
|
ex.printStackTrace(printWriter);
|
Throwable cause = ex.getCause();
|
while (cause != null) {
|
cause.printStackTrace(printWriter);
|
cause = ex.getCause();
|
}
|
printWriter.close();
|
stringBuilder.append(printWriter.toString());
|
// FileUtils.writeFile(Config.errorLog, stringBuilder.toString(), new CallBack() {
|
// @Override
|
// public void onSuccess(Object result) {
|
//
|
// }
|
//
|
// @Override
|
// public void onFailure(String errMsg) {
|
//
|
// }
|
//
|
// @Override
|
// public void onProcess(long cur, long total) {
|
//
|
// }
|
// });
|
}
|
}
|