Created
June 1, 2020 15:58
-
-
Save Apsaliya/4727979addb570a9c2242242d68edccc to your computer and use it in GitHub Desktop.
On Activity result
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
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