Created
September 7, 2025 10:41
-
-
Save root-ansh/58cfa3dd52766f88dd0bddf9fff7f063 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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