Skip to content

Instantly share code, notes, and snippets.

@navczydev
Created June 10, 2022 02:08
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 navczydev/63f434e5f7ef2e92ce2e7f0fb4fb2559 to your computer and use it in GitHub Desktop.
Save navczydev/63f434e5f7ef2e92ce2e7f0fb4fb2559 to your computer and use it in GitHub Desktop.
// create ActivityResultContract
val getContent =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
result?.let { nonNullableResult ->
when (nonNullableResult.resultCode == RESULT_OK) {
true -> {
val intent = nonNullableResult.data
intent?.data?.let { uri ->
// process data
}
}
false -> {
}
}
}
}
// launch the intent on button click
binding.fab.setOnClickListener {
Log.d(TAG, "onCreate:${MediaStore.getPickImagesMaxLimit()}")
val intent = Intent(MediaStore.ACTION_PICK_IMAGES).apply {
type = "image/*"
}
getContent.launch(intent)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment