Skip to content

Instantly share code, notes, and snippets.

@root-ansh
Created September 7, 2025 10:35
Show Gist options
  • Select an option

  • Save root-ansh/a248d60d6f50b9d6d80ebad07378ff7d to your computer and use it in GitHub Desktop.

Select an option

Save root-ansh/a248d60d6f50b9d6d80ebad07378ff7d to your computer and use it in GitHub Desktop.
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
type = "image/*" //"application/pdf" // "*/*"
putExtra(Intent.EXTRA_MIME_TYPES, arrayOf("image/*")) // required in some android versions. also good if you set type as */* and want to filter mimetypes
addCategory(Intent.CATEGORY_OPENABLE)
addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION or Intent.FLAG_GRANT_READ_URI_PERMISSION)// optional for our app, but required if you intend to save the SAF content uris(temporary by nature) in databases
}
getFileFromSystem.launch(intent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment