mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
#1520 Catch IllegalArgumentException
This commit is contained in:
parent
cca60df69f
commit
7fbbf842fd
@ -17,10 +17,12 @@
|
||||
*/
|
||||
package org.kiwix.kiwixmobile.utils.files
|
||||
|
||||
import android.annotation.TargetApi
|
||||
import android.content.ContentUris
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Build.VERSION_CODES
|
||||
import android.os.Environment
|
||||
import android.provider.DocumentsContract
|
||||
import android.util.Log
|
||||
@ -160,9 +162,23 @@ object FileUtils {
|
||||
if (documentId[0] == "primary") {
|
||||
return "${Environment.getExternalStorageDirectory()}/${documentId[1]}"
|
||||
}
|
||||
} else if ("com.android.providers.downloads.documents" == uri.authority
|
||||
)
|
||||
return contentQuery(
|
||||
} else if ("com.android.providers.downloads.documents" == uri.authority)
|
||||
return try {
|
||||
documentProviderContentQuery(ctx, uri)
|
||||
} catch (ignore: IllegalArgumentException) {
|
||||
null
|
||||
}
|
||||
} else if ("content".equals(uri.scheme!!, ignoreCase = true)) {
|
||||
return contentQuery(ctx, uri)
|
||||
} else if ("file".equals(uri.scheme!!, ignoreCase = true)) {
|
||||
return uri.path
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
@TargetApi(VERSION_CODES.KITKAT)
|
||||
private fun documentProviderContentQuery(ctx: Context, uri: Uri) =
|
||||
contentQuery(
|
||||
ctx,
|
||||
ContentUris.withAppendedId(
|
||||
Uri.parse("content://downloads/public_downloads"),
|
||||
@ -173,13 +189,6 @@ object FileUtils {
|
||||
}
|
||||
)
|
||||
)
|
||||
} else if ("content".equals(uri.scheme!!, ignoreCase = true)) {
|
||||
return contentQuery(ctx, uri)
|
||||
} else if ("file".equals(uri.scheme!!, ignoreCase = true)) {
|
||||
return uri.path
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private fun contentQuery(
|
||||
context: Context,
|
||||
|
Loading…
x
Reference in New Issue
Block a user