There are of course, many ways on Android to take a picture or record a video. The easiest way to capture an image is by using an intent to launch the camera app and grabbing the results once the image has been taken.
Launching a camera intent typically goes like this:
In Android Studio, create a new project.
In the
activity_main.xml
layout, add a new button and an image view. Name the image viewimage
.Create an on-click handler for that button.
Call the
takePicture
method from the event handler implementation.Implement the
takePicture
method. If supported by the device, launch the capture intent:static final int REQUEST_IMAGE_CAPTURE = 1; private void takePicture() { Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (captureIntent.resolveActivity( getPackageManager()) != null) { startActivityForResult(captureIntent, ...