Check EXTRA_MIME_TYPES instead of splitting type

This commit is contained in:
Callum Moffat 2025-02-14 02:46:22 -05:00
parent e3b18a5830
commit 1b1e190cd9

View file

@ -889,11 +889,15 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
private fun isGetContentIntent(intent: Intent) = intent.action == Intent.ACTION_GET_CONTENT && intent.type != null private fun isGetContentIntent(intent: Intent) = intent.action == Intent.ACTION_GET_CONTENT && intent.type != null
private fun anyExtraMimeTypeStartingWith(intent: Intent, mimeTypePrefix: String): Boolean {
return intent.getStringArrayExtra(Intent.EXTRA_MIME_TYPES)?.any { it.startsWith(mimeTypePrefix) } ?: false
}
private fun isGetImageContentIntent(intent: Intent) = isGetContentIntent(intent) && private fun isGetImageContentIntent(intent: Intent) = isGetContentIntent(intent) &&
(intent.type!!.split(",", "|").any { it.startsWith("image/") } || intent.type == Images.Media.CONTENT_TYPE) (intent.type!!.startsWith("image/") || intent.type == Images.Media.CONTENT_TYPE || anyExtraMimeTypeStartingWith(intent, "image/"))
private fun isGetVideoContentIntent(intent: Intent) = isGetContentIntent(intent) && private fun isGetVideoContentIntent(intent: Intent) = isGetContentIntent(intent) &&
(intent.type!!.split(",", "|").any { it.startsWith("video/") } || intent.type == Video.Media.CONTENT_TYPE) (intent.type!!.startsWith("video/") || intent.type == Video.Media.CONTENT_TYPE || anyExtraMimeTypeStartingWith(intent, "video/"))
private fun isGetAnyContentIntent(intent: Intent) = isGetContentIntent(intent) && intent.type == "*/*" private fun isGetAnyContentIntent(intent: Intent) = isGetContentIntent(intent) && intent.type == "*/*"