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