Skip to content

Instantly share code, notes, and snippets.

@rajumark
Created December 7, 2022 17:54
Show Gist options
  • Save rajumark/27327b4eb9c5744de704b392981646b0 to your computer and use it in GitHub Desktop.
Save rajumark/27327b4eb9c5744de704b392981646b0 to your computer and use it in GitHub Desktop.
pick folder using system tree view then use it
val dirRequest =
registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) { uri: Uri? ->
uri?.let { folderUri ->
contentResolver.takePersistableUriPermission(
folderUri,
Intent.FLAG_GRANT_READ_URI_PERMISSION
)
//use picked uri android
onFolderPickerResult?.invoke(folderUri)
}
}
//call to start folder picker in tree view
dirRequest.launch(null)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment