From 16383785e0acb3d690982183ef25776ecf413263 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Palyart Lamarche Date: Tue, 26 Jan 2021 10:44:14 +0100 Subject: [PATCH 1/7] [A] file name for content resolver if possible --- .../flutter_absolute_path/FileDirectory.kt | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/android/src/main/kotlin/com/kasem/flutter_absolute_path/FileDirectory.kt b/android/src/main/kotlin/com/kasem/flutter_absolute_path/FileDirectory.kt index 47b955b..9dd1c2f 100644 --- a/android/src/main/kotlin/com/kasem/flutter_absolute_path/FileDirectory.kt +++ b/android/src/main/kotlin/com/kasem/flutter_absolute_path/FileDirectory.kt @@ -8,6 +8,7 @@ import android.os.Build import android.os.Environment import android.provider.DocumentsContract import android.provider.MediaStore +import android.provider.OpenableColumns import java.io.* import java.util.* @@ -87,7 +88,10 @@ object FileDirectory { selectionArgs: Array?): String? { if (uri.authority != null) { - val targetFile = File(context.cacheDir, "IMG_${Date().time}.png") + // try to get file name + val filename = uri.contentSchemeFileName() + + val targetFile = File(context.cacheDir, filename ?: "IMG_${Date().time}.png") context.contentResolver.openInputStream(uri)?.use { input -> FileOutputStream(targetFile).use { fileOut -> input.copyTo(fileOut) @@ -136,4 +140,16 @@ object FileDirectory { fun isMediaDocument(uri: Uri): Boolean { return "com.android.providers.media.documents" == uri.authority } + + private fun Uri.contentSchemeFileName(): String? { + var fileName: String? = null + contentResolver.query(this, null, null, null, null)?.use { cursor -> + if (!cursor.moveToFirst()) return@use null + val name = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME) + fileName = cursor.getString(name) + cursor.close() + } + return fileName + } + } From 85b7df25e08054b33e9e8bf0f4c24da8caf8f55d Mon Sep 17 00:00:00 2001 From: Jean-Christophe Palyart Lamarche Date: Tue, 26 Jan 2021 10:56:15 +0100 Subject: [PATCH 2/7] [A] file name for content resolver if possible --- .../flutter_absolute_path/FileDirectory.kt | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/android/src/main/kotlin/com/kasem/flutter_absolute_path/FileDirectory.kt b/android/src/main/kotlin/com/kasem/flutter_absolute_path/FileDirectory.kt index 9dd1c2f..e518b4d 100644 --- a/android/src/main/kotlin/com/kasem/flutter_absolute_path/FileDirectory.kt +++ b/android/src/main/kotlin/com/kasem/flutter_absolute_path/FileDirectory.kt @@ -9,6 +9,7 @@ import android.os.Environment import android.provider.DocumentsContract import android.provider.MediaStore import android.provider.OpenableColumns +import com.kasem.flutter_absolute_path.FileDirectory.contentSchemeFileName import java.io.* import java.util.* @@ -89,7 +90,13 @@ object FileDirectory { if (uri.authority != null) { // try to get file name - val filename = uri.contentSchemeFileName() + val filename :String? = null + context.contentResolver.query(this, null, null, null, null)?.use { cursor -> + if (!cursor.moveToFirst()) return@use null + val nameColumIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME) + fileName = cursor.getString(nameColumIndex) + cursor.close() + } val targetFile = File(context.cacheDir, filename ?: "IMG_${Date().time}.png") context.contentResolver.openInputStream(uri)?.use { input -> @@ -141,15 +148,4 @@ object FileDirectory { return "com.android.providers.media.documents" == uri.authority } - private fun Uri.contentSchemeFileName(): String? { - var fileName: String? = null - contentResolver.query(this, null, null, null, null)?.use { cursor -> - if (!cursor.moveToFirst()) return@use null - val name = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME) - fileName = cursor.getString(name) - cursor.close() - } - return fileName - } - } From 533173918b34b458f65b9e77ef9626193b6a5906 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Palyart Lamarche Date: Tue, 26 Jan 2021 11:00:34 +0100 Subject: [PATCH 3/7] [A] file name for content resolver if possible --- .../kotlin/com/kasem/flutter_absolute_path/FileDirectory.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/android/src/main/kotlin/com/kasem/flutter_absolute_path/FileDirectory.kt b/android/src/main/kotlin/com/kasem/flutter_absolute_path/FileDirectory.kt index e518b4d..cef2837 100644 --- a/android/src/main/kotlin/com/kasem/flutter_absolute_path/FileDirectory.kt +++ b/android/src/main/kotlin/com/kasem/flutter_absolute_path/FileDirectory.kt @@ -9,7 +9,6 @@ import android.os.Environment import android.provider.DocumentsContract import android.provider.MediaStore import android.provider.OpenableColumns -import com.kasem.flutter_absolute_path.FileDirectory.contentSchemeFileName import java.io.* import java.util.* @@ -90,8 +89,8 @@ object FileDirectory { if (uri.authority != null) { // try to get file name - val filename :String? = null - context.contentResolver.query(this, null, null, null, null)?.use { cursor -> + var filename :String? = null + context.contentResolver.query(uri, null, null, null, null)?.use { cursor -> if (!cursor.moveToFirst()) return@use null val nameColumIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME) fileName = cursor.getString(nameColumIndex) From bd8d7b4f9976c1a8705a3cd593ce4a0ae3936966 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Palyart Lamarche Date: Tue, 26 Jan 2021 11:06:06 +0100 Subject: [PATCH 4/7] [A] file name for content resolver if possible --- .../kotlin/com/kasem/flutter_absolute_path/FileDirectory.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/src/main/kotlin/com/kasem/flutter_absolute_path/FileDirectory.kt b/android/src/main/kotlin/com/kasem/flutter_absolute_path/FileDirectory.kt index cef2837..9161b12 100644 --- a/android/src/main/kotlin/com/kasem/flutter_absolute_path/FileDirectory.kt +++ b/android/src/main/kotlin/com/kasem/flutter_absolute_path/FileDirectory.kt @@ -93,7 +93,7 @@ object FileDirectory { context.contentResolver.query(uri, null, null, null, null)?.use { cursor -> if (!cursor.moveToFirst()) return@use null val nameColumIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME) - fileName = cursor.getString(nameColumIndex) + filename = cursor.getString(nameColumIndex) cursor.close() } From 68539518c440a9328109b6c462491583af7b801b Mon Sep 17 00:00:00 2001 From: Jean-Christophe Palyart Lamarche Date: Tue, 26 Jan 2021 11:15:59 +0100 Subject: [PATCH 5/7] [A] file name for content resolver if possible --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 7339021..0f1fc2f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,4 +1,4 @@ -name: flutter_absolute_path +name: flutter_absolute_path_fork description: A flutter plugin that finds the absolute path of a file in iOS or Android devices. version: 1.0.6 author: Kasem SAEED From 5801b2827bc03c8e24250c2bf5543a30d418a483 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Palyart Lamarche Date: Tue, 26 Jan 2021 11:30:54 +0100 Subject: [PATCH 6/7] [A] file name for content resolver if possible --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 0f1fc2f..7339021 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,4 +1,4 @@ -name: flutter_absolute_path_fork +name: flutter_absolute_path description: A flutter plugin that finds the absolute path of a file in iOS or Android devices. version: 1.0.6 author: Kasem SAEED From d11e7216ed760438549c653c778b8df6e53f3200 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Palyart Lamarche Date: Tue, 26 Jan 2021 12:44:02 +0100 Subject: [PATCH 7/7] [A] file name for content resolver if possible --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 7339021..56f7514 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_absolute_path description: A flutter plugin that finds the absolute path of a file in iOS or Android devices. -version: 1.0.6 +version: 1.0.6-patch2 author: Kasem SAEED homepage: https://github.com/KasemJaffer/flutter_absolute_path