コード例 #1
0
  @Override
  public void uncaughtException(Thread thread, Throwable ex) {
    try {
      final Writer result = new StringWriter();
      final PrintWriter printWriter = new PrintWriter(result);
      ex.printStackTrace(printWriter);
      String errorReport =
          String.format(
              "[%s]\nAndroidVersion=%s\nIMEI=%s\nID=%s\n%s",
              new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()),
              VERSION.RELEASE,
              getIMEI(),
              Preference.getUsername(mAppContext),
              result.toString());

      Log.e(LOGTAG, errorReport);

      File logFile = new File(mAppContext.getFilesDir(), LOG_FILE);
      FileWriter fw = new FileWriter(logFile, true);

      fw.write(errorReport);

      fw.flush();
      fw.close();

    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      android.os.Process.killProcess(android.os.Process.myPid());
    }
  }