@ -92,7 +92,7 @@ object FileUtils {
// ExternalStorageProvider
if ( isExternalStorageDocument ( uri ) ) {
val docId = DocumentsContract . getDocumentId ( uri )
val split = docId . split ( " : " . toRegex ( ) ) . dropLastWhile { it . isEmpty ( ) } . toTypedArray ( )
val split = docId . split ( " : " )
val type = split [ 0 ]
if ( " primary " . equals ( type , ignoreCase = true ) ) {
@ -101,7 +101,7 @@ object FileUtils {
} else if ( isDownloadsDocument ( uri ) ) {
val id = DocumentsContract . getDocumentId ( uri )
val split = id . split ( " : " ) . dropLastWhile { it . isEmpty ( ) } . toTypedArray ( )
val split = id . split ( " : " )
val type = split [ 0 ]
if ( " raw " . equals ( type , ignoreCase = true ) ) {
//处理某些机型(比如Google Pixel )ID是raw:/storage/emulated/0/Download/c20f8664da05ab6b4644913048ea8c83.mp4
@ -115,14 +115,13 @@ object FileUtils {
return getDataColumn ( context , contentUri , null , null )
} else if ( isMediaDocument ( uri ) ) {
val docId = DocumentsContract . getDocumentId ( uri )
val split = docId . split ( " : " . toRegex ( ) ) . dropLastWhile { it . isEmpty ( ) } . toTypedArray ( )
val type = split [ 0 ]
val split = docId . split ( " : " . toRegex ( ) )
var contentUri : Uri ? = null
when ( type ) {
" image " -> contentUri = MediaStore . Images . Media . EXTERNAL _CONTENT _URI
" vide o" -> contentUri = MediaStore . Vide o. Media . EXTERNAL _CONTENT _URI
" audio " -> contentUri = MediaStore . Audio . Media . EXTERNAL _CONTENT _URI
val contentUri : Uri = when ( split [ 0 ] ) {
" image " -> MediaStore . Images . Media . EXTERNAL _CONTENT _URI
" video " -> MediaStore . Video . Media . EXTERNAL _CONTENT _URI
" audi o" -> MediaStore . Audi o. Media . EXTERNAL _CONTENT _URI
else -> uri
}
val selection = " _id=? "
@ -137,7 +136,6 @@ object FileUtils {
uri . lastPathSegment
else
getDataColumn ( context , uri , null , null )
} else if ( " file " . equals ( uri . scheme , ignoreCase = true ) ) {
return uri . path
} // File
@ -145,8 +143,8 @@ object FileUtils {
return null
}
fun getDataColumn (
context : Context , uri : Uri ? , selection : String ? ,
private fun getDataColumn (
context : Context , uri : Uri , selection : String ? ,
selectionArgs : kotlin . Array < String > ?
) : String ? {
@ -155,7 +153,7 @@ object FileUtils {
try {
context . contentResolver . query (
uri !! ,
uri ,
projection ,
selection ,
selectionArgs ,
@ -177,7 +175,7 @@ object FileUtils {
* @param uri The Uri to check .
* @return Whether the Uri authority is ExternalStorageProvider .
* /
fun isExternalStorageDocument ( uri : Uri ) : Boolean {
private fun isExternalStorageDocument ( uri : Uri ) : Boolean {
return " com.android.externalstorage.documents " == uri . authority
}
@ -185,7 +183,7 @@ object FileUtils {
* @param uri The Uri to check .
* @return Whether the Uri authority is DownloadsProvider .
* /
fun isDownloadsDocument ( uri : Uri ) : Boolean {
private fun isDownloadsDocument ( uri : Uri ) : Boolean {
return " com.android.providers.downloads.documents " == uri . authority
}
@ -193,7 +191,7 @@ object FileUtils {
* @param uri The Uri to check .
* @return Whether the Uri authority is MediaProvider .
* /
fun isMediaDocument ( uri : Uri ) : Boolean {
private fun isMediaDocument ( uri : Uri ) : Boolean {
return " com.android.providers.media.documents " == uri . authority
}
@ -201,7 +199,7 @@ object FileUtils {
* @param uri The Uri to check .
* @return Whether the Uri authority is Google Photos .
* /
fun isGooglePhotosUri ( uri : Uri ) : Boolean {
private fun isGooglePhotosUri ( uri : Uri ) : Boolean {
return " com.google.android.apps.photos.content " == uri . authority
}