Skip to content

Instantly share code, notes, and snippets.

@root-ansh
Created September 7, 2025 10:41
Show Gist options
  • Save root-ansh/58cfa3dd52766f88dd0bddf9fff7f063 to your computer and use it in GitHub Desktop.
Save root-ansh/58cfa3dd52766f88dd0bddf9fff7f063 to your computer and use it in GitHub Desktop.
private val saveFileToSystemSAF: ActivityResultLauncher<String> = registerForActivityResult(CreateDocument(mimeType = "*/*")) { result -> // or mimeType = "application/pdf" / "image/*"
val uri = result
val file = state.fileToBeSaved // the file/bitmap that needs to be writteen to user selected uri
val context = this
if (uri!=null && file!=null){
lifecycleScope.launch {
context.saveFileToUserSelectedPath(uri,file) // writing file to user selected uri
Snackbar
.make(binding.root,"Saved file :${file.name} to user selected directory", Snackbar.LENGTH_SHORT)
.setAction("show"){context.openSystemViewerForSAFUri(uri)} //check next section for info on this
.show()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment