Last active
November 6, 2021 23:25
-
-
Save plnice/c5810e0629733b7fc4150b1b0b43ea6a to your computer and use it in GitHub Desktop.
Simple ActivityResultContract
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
class MyContract : ActivityResultContract<Int, String>() { | |
companion object { | |
const val ACTION = "com.myapp.action.MY_ACTION" | |
const val INPUT_INT = "input_int" | |
const val OUTPUT_STRING = "output_string" | |
} | |
override fun createIntent(input: Int): Intent { | |
return Intent(ACTION) | |
.apply { putExtra(INPUT_INT, input) } | |
} | |
override fun parseResult(resultCode: Int, intent: Intent?): String? { | |
return when (resultCode) { | |
Activity.RESULT_OK -> intent?.getStringExtra(OUTPUT_STRING) | |
else -> null | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it even hard to understand for me, in an example first I have to get the image from take a picture, an image from directory Image o from Camera, What do I have to do for only choose a file from camera pictures?