public void getLogToLocal(Throwable e) {
StringBuffer sb = new StringBuffer();
Writer write = new StringWriter();
PrintWriter print = new PrintWriter(write);
e.printStackTrace(print);
print.close();
String string = write.toString();
long currentTimeMillis = System.currentTimeMillis();
String format = sim.format(currentTimeMillis);
sb.append(format + "\n\r");
sb.append(string);
String fileName = "crash-" + format + "-" + currentTimeMillis + ".txt";
String file_dir = getFilePath();
File dir = new File(file_dir);
if (!dir.exists()) {
dir.mkdirs();
}
File file = new File(file_dir + fileName);
try {
if (!file.exists()) {
file.createNewFile();
}
FileOutputStream fos = new FileOutputStream(file);
fos.write(sb.toString().getBytes());
fos.close();
} catch (Exception e1) {
e1.printStackTrace();
}
}
private String getFilePath() {
String file_dir = "";
boolean isSDCardExist = Environment.MEDIA_MOUNTED.equals(Environment
.getExternalStorageState());
boolean isRootDirExist = Environment.getExternalStorageDirectory()
.exists();
if (isSDCardExist && isRootDirExist) {
file_dir = Environment.getExternalStorageDirectory()
.getAbsolutePath() + "/openhapplog/";
} else {
file_dir = getApplicationContext().getFilesDir().getAbsolutePath()
+ "/openhappLog/";
}
return file_dir;
}