Skip to content

Commit 6add0a1

Browse files
committed
( fix #33 ) work with apps that requests ".nomedia" suffix on files
1 parent 5f2a1d8 commit 6add0a1

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

app/src/main/java/com/todobom/opennotescanner/OpenNoteScannerActivity.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -886,18 +886,28 @@ public void saveDocument(ScannedDocument scannedDocument) {
886886

887887
Core.flip(doc.t(), endDoc, 1);
888888

889-
Imgcodecs.imwrite(fileName, endDoc);
889+
String suffix = "";
890+
if (isIntent && fileName.endsWith(".nomedia")) {
891+
suffix = ".jpg";
892+
}
890893

891-
try {
892-
ExifInterface exif = new ExifInterface(fileName);
893-
exif.setAttribute("UserComment", "Generated using Open Note Scanner");
894-
// exif.setAttribute(ExifInterface.TAG_ORIENTATION,Integer.valueOf(ExifInterface.ORIENTATION_ROTATE_180).toString());
895-
exif.saveAttributes();
896-
} catch (IOException e) {
897-
e.printStackTrace();
894+
Imgcodecs.imwrite(fileName+suffix, endDoc);
895+
896+
if (isIntent && !suffix.isEmpty()) {
897+
File orig = new File(fileName+suffix);
898+
orig.renameTo(new File(fileName));
898899
}
899900

900-
addImageToGallery(fileName , this);
901+
if ((fileName+suffix).endsWith(".jpg")) {
902+
try {
903+
ExifInterface exif = new ExifInterface(fileName);
904+
exif.setAttribute("UserComment", "Generated using Open Note Scanner");
905+
// exif.setAttribute(ExifInterface.TAG_ORIENTATION,Integer.valueOf(ExifInterface.ORIENTATION_ROTATE_180).toString());
906+
exif.saveAttributes();
907+
} catch (IOException e) {
908+
e.printStackTrace();
909+
}
910+
}
901911

902912
animateDocument(fileName,scannedDocument);
903913

@@ -906,6 +916,8 @@ public void saveDocument(ScannedDocument scannedDocument) {
906916
if (isIntent) {
907917
setResult(RESULT_OK, intent);
908918
finish();
919+
} else {
920+
addImageToGallery(fileName , this);
909921
}
910922

911923
// Record goal "PictureTaken"

0 commit comments

Comments
 (0)