76.4 Handling Intent Results
Since we are launching intents which will return a result, the registerForActivityResult() method (covered in the chapter entitled “Android Explicit Intents – A Worked Example”) needs to be used to create a launcher and declare a lambda to handle the returned data, for example:
val startOpenForResult = registerForActivityResult(
ActivityResultContracts.StartActivityForResult()) {
result: ActivityResult ->
if (result.resultCode == Activity.RESULT_OK) {
result.data?.let {
val currentUri = it.data
currentUri?.let {
// Read file content...