Last active
August 29, 2023 16:00
-
-
Save Kurante2801/828596e27b43ede86a8267bc0885909b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* inside activity class */ | |
private val launcher = registerForActivityResult(OpenDocumentTreePersistent()) { uri: Uri? -> | |
if (uri != null) | |
contentResolver.takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION) | |
/* ... */ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OpenDocumentTreePersistent : OpenDocumentTree() { | |
override fun createIntent(context: Context, input: Uri?): Intent { | |
val intent = super.createIntent(context, input) | |
intent.addFlags( | |
Intent.FLAG_GRANT_READ_URI_PERMISSION | |
or Intent.FLAG_GRANT_WRITE_URI_PERMISSION | |
or Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION | |
or Intent.FLAG_GRANT_PREFIX_URI_PERMISSION | |
) | |
return intent | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment