Skip to content

Instantly share code, notes, and snippets.

@mirjalal
Forked from kingargyle/multifilepicker.java
Last active June 28, 2019 12:20
Show Gist options
  • Save mirjalal/da0be5febe24b973dc292a1c9ddf00ef to your computer and use it in GitHub Desktop.
Save mirjalal/da0be5febe24b973dc292a1c9ddf00ef to your computer and use it in GitHub Desktop.
Android 4.4+ Select Multiple Files with UI File Picker
val intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
startActivityForResult(intent, 1)
// In code that handles the result returned to process the files:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == 1) {
if (data != null) {
val clipData = data.clipData
if (clipData != null) println("clipData.itemCount: ${clipData.itemCount}")
else println(data.data?.toFile()?.name)
} else println("intent is null")
} else println(requestCode)
}
// All data is returned in the ClipData object and item count contains the number of items returned.
// Content is the URI for each file to be resolved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment