Search code examples
androidandroid-camera

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?


Solution

  • 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>