I want to open a camera of a device when we click on a button in our app. Please help me out.
This example demonstrates how do I click camera programmatically in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml.
The fastest way to launch the camera takes advantage of the phone’s power button. This method doesn’t require any swiping or unlocking. It’s super fast, and your Android device most likely supports it. All you need to do is double-press the power button. If your device supports it, the camera will immediately launch.
To call the camera you can use: Intent intent = new Intent ("android.media.action.IMAGE_CAPTURE"); startActivity (intent); The image will be automatically saved in a default directory. And you need to set the permission for the camera in your AndroidManifest.xml:
It only opens the camera. You’ll need to properly unlock the device to leave the camera. The fastest way to launch the camera takes advantage of the phone’s power button. This method doesn’t require any swiping or unlocking. It’s super fast, and your Android device most likely supports it. All you need to do is double-press the power button.
Inside Button's onClick,
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, 0);
And add Camers Uses Permission in your manifest file.
<uses-permission android:name="android.permission.CAMERA"></uses-permission>
See the additional discussion here Android camera intent
Use this
BtnSelectImage.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View v)
{
startCamera();
Intent intent=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI.getPath());
startActivityForResult(intent, 1);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With