|
|
@ -73,7 +73,7 @@ public class BackupUtils {
|
|
|
|
return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
|
|
|
|
return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int exportToText() {
|
|
|
|
public int exportToText() throws IOException {
|
|
|
|
return mTextExport.exportToText();
|
|
|
|
return mTextExport.exportToText();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -218,7 +218,7 @@ public class BackupUtils {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Note will be exported as text which is user readable
|
|
|
|
* Note will be exported as text which is user readable
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public int exportToText() {
|
|
|
|
public int exportToText() throws IOException {
|
|
|
|
if (!externalStorageAvailable()) {
|
|
|
|
if (!externalStorageAvailable()) {
|
|
|
|
Log.d(TAG, "Media was not mounted");
|
|
|
|
Log.d(TAG, "Media was not mounted");
|
|
|
|
return STATE_SD_CARD_UNMOUONTED;
|
|
|
|
return STATE_SD_CARD_UNMOUONTED;
|
|
|
@ -285,26 +285,25 @@ public class BackupUtils {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Get a print stream pointed to the file {@generateExportedTextFile}
|
|
|
|
* Get a print stream pointed to the file {@generateExportedTextFile}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private PrintStream getExportToTextPrintStream() {
|
|
|
|
private PrintStream getExportToTextPrintStream() throws IOException {
|
|
|
|
File file = generateFileMountedOnSDcard(mContext, R.string.file_path,
|
|
|
|
File file = generateFileMountedOnSDcard(mContext, R.string.file_path,
|
|
|
|
R.string.file_name_txt_format);
|
|
|
|
R.string.file_name_txt_format);
|
|
|
|
if (file == null) {
|
|
|
|
if (file == null) {
|
|
|
|
Log.e(TAG, "create file to exported failed");
|
|
|
|
Log.e(TAG, "create file to exported failed");
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mFileName = file.getName();
|
|
|
|
mFileName = file.getName();
|
|
|
|
mFileDirectory = mContext.getString(R.string.file_path);
|
|
|
|
mFileDirectory = mContext.getString(R.string.file_path);
|
|
|
|
PrintStream ps = null;
|
|
|
|
PrintStream ps = null;
|
|
|
|
try {
|
|
|
|
|
|
|
|
FileOutputStream fos = new FileOutputStream(file);
|
|
|
|
try (FileOutputStream fos = new FileOutputStream(file)) {
|
|
|
|
ps = new PrintStream(fos);
|
|
|
|
ps = new PrintStream(fos);
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
ps.close();
|
|
|
|
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
} catch (NullPointerException e) {
|
|
|
|
} catch (NullPointerException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
ps.close();
|
|
|
|
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ps;
|
|
|
|
return ps;
|
|
|
@ -330,7 +329,12 @@ public class BackupUtils {
|
|
|
|
filedir.mkdir();
|
|
|
|
filedir.mkdir();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!file.exists()) {
|
|
|
|
if (!file.exists()) {
|
|
|
|
file.createNewFile();
|
|
|
|
boolean res = file.createNewFile();
|
|
|
|
|
|
|
|
if (res == true) {
|
|
|
|
|
|
|
|
Log.i("BackupUtils", "Create new file sucessfully");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Log.i("BackupUtils", "Fail to create new file");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return file;
|
|
|
|
return file;
|
|
|
|
} catch (SecurityException e) {
|
|
|
|
} catch (SecurityException e) {
|
|
|
|