diff --git a/CHANGELOG.md b/CHANGELOG.md index 8384220..4a334f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ -## 2.1.2 -Fixed desktop plugin implementation +## 2.1.3 +Android: Updates file name handling method. ([#487](https://github.com/miguelpruivo/flutter_file_picker/issues/487)). +Desktop (Go): Fixed desktop plugin implementation (thank you @DenchikBY). ## 2.1.1 iOS: Fixes an issue that could result in a crash when selecting a media item twice. ([#518](https://github.com/miguelpruivo/flutter_file_picker/issues/518)). diff --git a/android/src/main/java/com/mr/flutter/plugin/filepicker/FileUtils.java b/android/src/main/java/com/mr/flutter/plugin/filepicker/FileUtils.java index 3d93cce..873dbf4 100644 --- a/android/src/main/java/com/mr/flutter/plugin/filepicker/FileUtils.java +++ b/android/src/main/java/com/mr/flutter/plugin/filepicker/FileUtils.java @@ -8,6 +8,7 @@ import android.net.Uri; import android.os.Build; import android.os.storage.StorageManager; import android.provider.DocumentsContract; +import android.provider.OpenableColumns; import android.util.Log; import android.webkit.MimeTypeMap; @@ -55,36 +56,30 @@ public class FileUtils { public static String getFileName(Uri uri, final Context context) { String result = null; - //if uri is content - if (uri.getScheme() != null && uri.getScheme().equals("content")) { - Cursor cursor = null; - try { - cursor = context.getContentResolver().query(uri, null, null, null, null); - if (cursor != null && cursor.moveToFirst()) { - //local filesystem - int index = cursor.getColumnIndex("_data"); - if (index == -1) - //google drive - { - index = cursor.getColumnIndex("_display_name"); + try { + + if (uri.getScheme().equals("content")) { + Cursor cursor = context.getContentResolver().query(uri, new String[]{OpenableColumns.DISPLAY_NAME}, null, null, null); + try { + if (cursor != null && cursor.moveToFirst()) { + result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); } - result = cursor.getString(index); - if (result != null) { - uri = Uri.parse(result); - } else { - return null; - } - } - } catch (final Exception ex) { - Log.e(TAG, "Failed to decode file name: " + ex.toString()); - } finally { - if (cursor != null) { + } finally { cursor.close(); } } + if (result == null) { + result = uri.getPath(); + int cut = result.lastIndexOf('/'); + if (cut != -1) { + result = result.substring(cut + 1); + } + } + } catch (Exception ex){ + Log.e(TAG, "Failed to handle file name: " + ex.toString()); } - return uri.toString(); + return result; } public static boolean clearCache(final Context context) { diff --git a/example/ios/Flutter/.last_build_id b/example/ios/Flutter/.last_build_id index 0b85c88..6f115ce 100644 --- a/example/ios/Flutter/.last_build_id +++ b/example/ios/Flutter/.last_build_id @@ -1 +1 @@ -0915ff87e81a3bfb122df4ced418a2b0 \ No newline at end of file +32b17685cd2c55cd4f786d731516419d \ No newline at end of file diff --git a/lib/src/platform_file.dart b/lib/src/platform_file.dart index 1fa810c..1e8a814 100644 --- a/lib/src/platform_file.dart +++ b/lib/src/platform_file.dart @@ -16,7 +16,7 @@ class PlatformFile { this.bytes = data['bytes'], this.size = data['size']; - /// The absolute path for a cached copy of this file. It can be used to create a + /// The absolute path for a cached copy of this file. It can be used to create a /// file instance with a descriptor for the given path. /// ``` /// final File myFile = File(platformFile.path); diff --git a/pubspec.yaml b/pubspec.yaml index 4a913b1..cb2e5de 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: file_picker description: A package that allows you to use a native file explorer to pick single or multiple absolute file paths, with extension filtering support. homepage: https://github.com/miguelpruivo/plugins_flutter_file_picker -version: 2.1.2 +version: 2.1.3 dependencies: flutter: