Skip to content

Commit 329782d

Browse files
committed
Improve file uri utils class
1 parent 114486f commit 329782d

File tree

1 file changed

+15
-7
lines changed
  • imagepicker/src/main/kotlin/com/github/drjacky/imagepicker/util

1 file changed

+15
-7
lines changed

imagepicker/src/main/kotlin/com/github/drjacky/imagepicker/util/FileUriUtils.kt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import android.os.Build
99
import android.os.Environment
1010
import android.provider.DocumentsContract
1111
import android.provider.MediaStore
12+
import android.util.Log
1213
import java.io.*
1314

1415
/**
@@ -62,24 +63,31 @@ object FileUriUtils {
6263
}
6364
}
6465
isDownloadsDocument(uri) -> {
65-
val fileName = getFilePath(context, uri)
66+
/*val fileName = getFilePath(context, uri)
6667
if (fileName != null) {
6768
val path = Environment.getExternalStorageDirectory()
6869
.toString() + "/Download/" + fileName
6970
if (File(path).exists()) {
7071
return path
7172
}
72-
}
73+
}*/
7374

7475
var id = DocumentsContract.getDocumentId(uri)
7576
if (id.contains(":")) {
7677
id = id.split(":")[1]
7778
}
78-
val contentUri = ContentUris.withAppendedId(
79-
Uri.parse("content://downloads/public_downloads"),
80-
java.lang.Long.valueOf(id)
81-
)
82-
return getDataColumn(context, contentUri, null, null)
79+
if (id.isNotBlank()) {
80+
return try {
81+
val contentUri = ContentUris.withAppendedId(
82+
Uri.parse("content://downloads/public_downloads"),
83+
java.lang.Long.valueOf(id)
84+
)
85+
getDataColumn(context, contentUri, null, null)
86+
} catch (e: NumberFormatException) {
87+
Log.i("ImagePicker", e.message.toString())
88+
null
89+
}
90+
}
8391
}
8492
isMediaDocument(uri) -> {
8593
val docId = DocumentsContract.getDocumentId(uri)

0 commit comments

Comments
 (0)