Component - Camera access
This UI component allows the user to open the device camera, take a photo, and display the captured image on the screen. It requests camera permission, shows a button to start the camera, and then shows the photo taken.
This UI component allows the user to open the device camera, take a photo, and display the captured image on the screen. It requests camera permission, shows a button to start the camera, and then shows the photo taken.
Activity ├── ConstraintLayout │ ├── Button (Take Photo) │ └── ImageView (Photo Preview)
MediaStore.ACTION_IMAGE_CAPTURE in an Android app?MediaStore.ACTION_IMAGE_CAPTURE is a predefined intent action to launch the camera app for capturing images.startActivityForResult requires an Intent and a request code integer.MediaStore.ACTION_IMAGE_CAPTURE as the action.override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
val photo = data?.extras?.get("data") as Bitmap
imageView.setImageBitmap(photo)
}
}val intent = Intent() intent.action = MediaStore.ACTION_IMAGE_CAPTURE startActivityForResult(intent)
MediaStore.EXTRA_OUTPUT before starting the intent.Pass the test and this pattern moves unknown