| | |
| | | import java.util.Locale; |
| | | import java.util.Map; |
| | | |
| | | public class CrashManager implements Thread.UncaughtExceptionHandler{ |
| | | public class CrashManager implements Thread.UncaughtExceptionHandler { |
| | | public static final String TAG = "CrashManager"; |
| | | private static final CrashManager INSTANCE = new CrashManager(); |
| | | private Context context; |
| | |
| | | return false; |
| | | } |
| | | ex.printStackTrace(); |
| | | LogUtils.e(ex); |
| | | if (ex != null) |
| | | LogUtils.e(ex); |
| | | collectDeviceInfo(context);// 收集设备参数信息 |
| | | saveCrashInfoToFile(ex);// 保存日志文件 |
| | | // 使用Toast显示异常信息 |
| | |
| | | |
| | | // 写入文件 |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.US); |
| | | String rootPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/ltNormalLogs/crash" ; |
| | | String rootPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/ltNormalLogs/crash"; |
| | | File ff = new File(rootPath); |
| | | if (!ff.exists() || !ff.isDirectory()){ |
| | | if (!ff.exists() || !ff.isDirectory()) { |
| | | ff.mkdir(); |
| | | } |
| | | String crashFileName = rootPath + "/crash_" + simpleDateFormat.format(new Date()) + ".log"; |
| | | try { |
| | | FileOutputStream fos =null; |
| | | FileOutputStream fos = null; |
| | | File logFile = new File(crashFileName); |
| | | if (logFile.exists()){ |
| | | fos = new FileOutputStream(crashFileName,true); |
| | | }else { |
| | | if (logFile.exists()) { |
| | | fos = new FileOutputStream(crashFileName, true); |
| | | } else { |
| | | fos = new FileOutputStream(crashFileName); |
| | | } |
| | | fos.write(stringBuffer.toString().getBytes()); |