Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android open camera from button

I hope this isn't a duplicate question but I am making an app that I want a button to open the camera app (the default android camera separately). How do I got about doing that? I know there is a function:

intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE) 

Do I need to use that? And how do I call the button from the xml file?

Also do I need to worry about storing that picture or video or will the default camera app take care of that?

like image 551
Ryan Sayles Avatar asked Dec 20 '12 17:12

Ryan Sayles


People also ask

How can I Open Camera on click button?

Intent intent = new Intent("android. media. action. IMAGE_CAPTURE"); startActivity(intent);

How do I quickly open the camera?

All you need to do is double-press the power button. If your device supports it, the camera will immediately launch. This works from anywhere.

How do I Open Camera with intent?

Intent camera_intent = new Intent(MediaStore. ACTION_IMAGE_CAPTURE); startActivityForResult(camera_intent, pic_id); Now use onActivityResult() method to get the result, here the captured image.


1 Answers

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:

<uses-permission android:name="android.permission.CAMERA"> </uses-permission> 
like image 140
captainDizzy Avatar answered Sep 28 '22 04:09

captainDizzy