From 14e3e8c40c82fd766e6633326778845d8adf8e06 Mon Sep 17 00:00:00 2001 From: Christofer Bodin Date: Thu, 10 Dec 2020 20:41:17 +0100 Subject: [PATCH] fix captured media filename having multiple suffixes --- .../InAppWebView/InAppWebViewChromeClient.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebViewChromeClient.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebViewChromeClient.java index 34761ca4..b0e09bb4 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebViewChromeClient.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebViewChromeClient.java @@ -1106,31 +1106,29 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR String prefix = ""; String suffix = ""; String dir = ""; - String filename = ""; if (intentType.equals(MediaStore.ACTION_IMAGE_CAPTURE)) { - prefix = "image-"; + prefix = "image"; suffix = ".jpg"; dir = Environment.DIRECTORY_PICTURES; } else if (intentType.equals(MediaStore.ACTION_VIDEO_CAPTURE)) { - prefix = "video-"; + prefix = "video"; suffix = ".mp4"; dir = Environment.DIRECTORY_MOVIES; } - filename = prefix + String.valueOf(System.currentTimeMillis()) + suffix; - // for versions below 6.0 (23) we use the old File creation & permissions model if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { // only this Directory works on all tested Android versions // ctx.getExternalFilesDir(dir) was failing on Android 5.0 (sdk 21) File storageDir = Environment.getExternalStoragePublicDirectory(dir); + String filename = String.format("%s-%d%s", prefix, System.currentTimeMillis(), suffix); return new File(storageDir, filename); } Activity activity = inAppBrowserActivity != null ? inAppBrowserActivity : Shared.activity; File storageDir = activity.getApplicationContext().getExternalFilesDir(null); - return File.createTempFile(filename, suffix, storageDir); + return File.createTempFile(prefix, suffix, storageDir); } private Boolean isArrayEmpty(String[] arr) {