Skip to content

Instantly share code, notes, and snippets.

@Apsaliya
Created June 1, 2020 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Apsaliya/4727979addb570a9c2242242d68edccc to your computer and use it in GitHub Desktop.
Save Apsaliya/4727979addb570a9c2242242d68edccc to your computer and use it in GitHub Desktop.
On Activity result
override fun onActivityResult(
requestCode: Int,
resultCode: Int,
resultIntent: Intent?
) {
lifecycleScope.launch {
if (resultCode == Activity.RESULT_OK && resultIntent != null) {
val uri = resultIntent.data!!
val pfd = contentResolver.openFileDescriptor(uri, "w")
pfd?.use {
FileOutputStream(pfd.fileDescriptor).use { outputStream ->
val file = packZipFileForBackup(context)
try {
file?.source()?.use inner2@{ input ->
return@inner2 outputStream.sink().buffer().use inner@{ output ->
output.writeAll(input)
}
}
} finally {
if (file?.exists() == true) {
file.delete()
}
}
}
}
}
}
super.onActivityResult(requestCode, resultCode, resultIntent)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment