Created
June 10, 2022 02:08
-
-
Save navczydev/63f434e5f7ef2e92ce2e7f0fb4fb2559 to your computer and use it in GitHub Desktop.
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
// 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