Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.*

Expand Down Expand Up @@ -87,7 +88,16 @@ object FileDirectory {
selectionArgs: Array<String>?): String? {

if (uri.authority != null) {
val targetFile = File(context.cacheDir, "IMG_${Date().time}.png")
// try to get file name
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)
cursor.close()
}

val targetFile = File(context.cacheDir, filename ?: "IMG_${Date().time}.png")
context.contentResolver.openInputStream(uri)?.use { input ->
FileOutputStream(targetFile).use { fileOut ->
input.copyTo(fileOut)
Expand Down Expand Up @@ -136,4 +146,5 @@ object FileDirectory {
fun isMediaDocument(uri: Uri): Boolean {
return "com.android.providers.media.documents" == uri.authority
}

}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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<kasem.jaffer@gmail.com>
homepage: https://github.com/KasemJaffer/flutter_absolute_path

Expand Down