Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

camera launch on button click in android

Tags:

android

I want to open a camera of a device when we click on a button in our app. Please help me out.

like image 704
Sanat Pandey Avatar asked Apr 26 '11 09:04

Sanat Pandey


People also ask

How do I click camera programmatically in Android?

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.

How do I launch the camera on my phone?

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.

How do I call a camera from an Android intent?

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:

How do I open the camera without swiping the screen?

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.


2 Answers

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

like image 166
Kartik Domadiya Avatar answered Sep 26 '22 17:09

Kartik Domadiya


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);
    }
});
like image 23
Guru Avatar answered Sep 22 '22 17:09

Guru