Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -389,13 +389,14 @@ class CustomWebChromeClient(private val context: Context) : WebChromeClient() {

private fun getMimeType(acceptTypes: Array<String>): String {
for (type in acceptTypes) {
return when (type) {
".json" -> "application/json"
".css" -> "text/css"
return when {
type == ".json" -> "application/json"
type == ".css" -> "text/css"
type.contains("/") -> type
else -> continue
}
Comment on lines +392 to 397
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Instead of hardcoding specific extensions like .json and .css, you can use android.webkit.MimeTypeMap to support a wider range of file types.

Also, note that this logic returns the first valid MIME type found and ignores any subsequent ones. If a web page specifies multiple types (e.g., accept="image/*, application/pdf"), the file picker will be restricted to only the first type, preventing the user from selecting others. For a more robust implementation, consider handling multiple MIME types or falling back to */* when more than one type is provided.

Suggested change
return when {
type == ".json" -> "application/json"
type == ".css" -> "text/css"
type.contains("/") -> type
else -> continue
}
return when {
type.startsWith(".") -> android.webkit.MimeTypeMap.getSingleton()
.getMimeTypeFromExtension(type.substring(1)) ?: continue
type.contains("/") -> type
else -> continue
}

}
return "application/octet-stream"
return "*/*"
}
}

Expand Down