mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-08 06:42:21 -04:00
#1520 Catch IllegalArgumentException
This commit is contained in:
parent
cca60df69f
commit
7fbbf842fd
@ -17,10 +17,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.kiwix.kiwixmobile.utils.files
|
package org.kiwix.kiwixmobile.utils.files
|
||||||
|
|
||||||
|
import android.annotation.TargetApi
|
||||||
import android.content.ContentUris
|
import android.content.ContentUris
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
import android.os.Build.VERSION_CODES
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import android.provider.DocumentsContract
|
import android.provider.DocumentsContract
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
@ -160,9 +162,23 @@ object FileUtils {
|
|||||||
if (documentId[0] == "primary") {
|
if (documentId[0] == "primary") {
|
||||||
return "${Environment.getExternalStorageDirectory()}/${documentId[1]}"
|
return "${Environment.getExternalStorageDirectory()}/${documentId[1]}"
|
||||||
}
|
}
|
||||||
} else if ("com.android.providers.downloads.documents" == uri.authority
|
} else if ("com.android.providers.downloads.documents" == uri.authority)
|
||||||
)
|
return try {
|
||||||
return contentQuery(
|
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,
|
ctx,
|
||||||
ContentUris.withAppendedId(
|
ContentUris.withAppendedId(
|
||||||
Uri.parse("content://downloads/public_downloads"),
|
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(
|
private fun contentQuery(
|
||||||
context: Context,
|
context: Context,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user