Skip to content

Instantly share code, notes, and snippets.

@plnice
Last active November 6, 2021 23:25
Show Gist options
  • Save plnice/c5810e0629733b7fc4150b1b0b43ea6a to your computer and use it in GitHub Desktop.
Save plnice/c5810e0629733b7fc4150b1b0b43ea6a to your computer and use it in GitHub Desktop.
Simple ActivityResultContract
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
}
}
}
@AngeMauriciolAntolin
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment