Skip to content

Commit

Permalink
Fix auto file conversion in android
Browse files Browse the repository at this point in the history
  • Loading branch information
natsuk4ze committed Aug 18, 2023
1 parent 4de2f3a commit 1230af6
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions android/src/main/java/studio/midoridesign/gal/GalPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ private void putMedia(Context context, String path, String album, boolean isImag
if (dotIndex == -1) throw new FileNotFoundException("Extension not found.");

try (InputStream in = new FileInputStream(file)) {
writeData(context, in, isImage, name.substring(dotIndex + 1), album);
writeData(context, in, isImage, name.substring(dotIndex), album);
}
}

private void putMediaBytes(Context context, byte[] bytes, String album)
throws IOException, SecurityException {
try (InputStream in = new ByteArrayInputStream(bytes)) {
writeData(context, in, true, "jpg", album);
writeData(context, in, true, ".jpg", album);
}
}

Expand All @@ -141,20 +141,20 @@ private void writeData(Context context, InputStream in, boolean isImage, String
ContentValues values = new ContentValues();
String dirPath = isImage || album != null ? Environment.DIRECTORY_PICTURES
: Environment.DIRECTORY_MOVIES;
String name = UUID.randomUUID().toString();

if (USE_EXTERNAL_STORAGE) {
File dir = new File(Environment.getExternalStoragePublicDirectory(dirPath),
album != null ? album : "");
if (!dir.exists()) dir.mkdirs();
String path =
dir.getPath() + File.separator + UUID.randomUUID().toString() + "." + extension;
String path = dir.getPath() + File.separator + name + extension;
values.put(MediaStore.MediaColumns.DATA, path);
} else {
String path = dirPath + (album != null ? File.separator + album : "");
values.put(isImage ? MediaStore.Images.Media.RELATIVE_PATH
: MediaStore.Video.Media.RELATIVE_PATH, path);
}

values.put(MediaStore.MediaColumns.DISPLAY_NAME, name + extension);
Uri uri = resolver.insert(isImage ? IMAGE_URI : VIDEO_URI, values);
try (OutputStream out = resolver.openOutputStream(uri)) {
byte[] buffer = new byte[8192];
Expand Down

0 comments on commit 1230af6

Please sign in to comment.