# Open Android Camera

**URL:** <https://discourse.processing.org/t/open-android-camera/23696>\
**Category:** Processing for Android\
**Created:** [September 5, 2020, 5:18pm UTC](https://discourse.processing.org/t/open-android-camera/23696 "2020-09-05T17:18:33Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dominik\_rgn](https://avatars.discourse-cdn.com/v4/letter/d/a9adbd/32.png) [@Dominik\_rgn](https://discourse.processing.org/u/Dominik_rgn)\
**Post date:** [September 5, 2020, 5:18pm UTC](https://discourse.processing.org/t/open-android-camera/23696/1 "2020-09-05T17:18:33Z")

</div>

Hello I wanted to ask how I can open a camera?

---

<div class="post-metadata">

**Author:** ![Bhavya22](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@Bhavya22](https://discourse.processing.org/u/Bhavya22)\
**Post date:** [December 28, 2020, 6:20pm UTC](https://discourse.processing.org/t/open-android-camera/23696/2 "2020-12-28T18:20:20Z")

</div>

Intent takePictureIntent = new Intent(MediaStore.ACTION\_IMAGE\_CAPTURE);  
mian thing you need to use is MediaStore.ACTION\_IMAGE\_CAPTURE to open the default camera  
For stroing in device or to upload to server you need to use different things.  
Like timestamp to store so that each file has different name and other things  
(For developing in android studio)

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [December 29, 2020, 11:35am UTC](https://discourse.processing.org/t/open-android-camera/23696/3 "2020-12-29T11:35:48Z")

</div>

@Bhavya ===  
yes, teh code below is the same than yours but more developped; of course permissioons are nedded and of  
course you have to nullify the camera onPause()

import android.app.Activity;  
import android.content.Intent;  
import android.net.Uri;  
import android.os.Bundle;  
import android.os.Environment;  
import android.provider.MediaStore;  
//import android.view.Menu;  
//import android.view.MenuItem;  
//import android.view.View;  
import android.widget.Toast;

public static final int LAUNCH\_CAM =1;  
public static final int CAMERA\_REQUEST = 2;  
//static int RESULT\_OK;

```auto
public void setup(){
  orientation(LANDSCAPE);
  Intent intent= new Intent(MediaStore.INTENT_ACTION_VIDEO_CAMERA);
  getActivity().startActivityForResult(intent, LAUNCH_CAM);
}

public void onActivityResult(int requestCode, int resultCode,Intent data)
    {
      if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK){
        //Toast.makeText(this, outPutfileUri.toString(),Toast.LENGTH_LONG).show();
        println("tout est ok------------------");
    }
  }

public void draw(){
  
  
  
}

```

---

<div class="post-metadata">

**Author:** ![Bhavya22](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@Bhavya22](https://discourse.processing.org/u/Bhavya22)\
**Post date:** [December 29, 2020, 11:56am UTC](https://discourse.processing.org/t/open-android-camera/23696/4 "2020-12-29T11:56:17Z")

</div>

@akenaton i think Action\_Video\_Camera will open the VideoCam directly. It may be possible that i am wrong but according to mediastore library i just saw action image capture for camera photos. and yes your onPause statement is right. Please let me know what exactly Action\_video\_camera can do I will also try it in my apps as well

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [December 29, 2020, 4:17pm UTC](https://discourse.processing.org/t/open-android-camera/23696/5 "2020-12-29T16:17:21Z")

</div>

@Bhavya22 === yes, you are right; ACTION\_VIDEO will launch the video cam , but when the video is on it is easy to take only a picture: i choose it because here, on this forum, a lot of people try to launch the cam, some for a video some others for only a picture…

---

<div class="post-metadata">

**Author:** ![Bhavya22](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@Bhavya22](https://discourse.processing.org/u/Bhavya22)\
**Post date:** [December 29, 2020, 4:37pm UTC](https://discourse.processing.org/t/open-android-camera/23696/6 "2020-12-29T16:37:52Z")

</div>

Ok i understood. Thanks for the clarification

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [December 30, 2020, 3:56pm UTC](https://discourse.processing.org/t/open-android-camera/23696/7 "2020-12-30T15:56:00Z")

</div>

@Bhavya22 === ok, put answered for others.

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [December 30, 2020, 4:09pm UTC](https://discourse.processing.org/t/open-android-camera/23696/8 "2020-12-30T16:09:03Z")

</div>

Might want to take a look at the kettai library or look at @noel github repo which has a lot of android examples.

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [December 31, 2020, 3:44pm UTC](https://discourse.processing.org/t/open-android-camera/23696/9 "2020-12-31T15:44:53Z")

</div>

@paulgoux === ??? - Is this code running?

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [December 31, 2020, 4:25pm UTC](https://discourse.processing.org/t/open-android-camera/23696/10 "2020-12-31T16:25:23Z")

</div>

if not this should get it working

```auto
import ketai.camera.*;
boolean mdown = false;
int counter = 0;

KetaiCamera cam;

void setup() {
  orientation(LANDSCAPE);
  cam = new KetaiCamera(this, 1280, 768, 30);
  println(cam.list()); // 1
  // 0: back camera; 1: front camera
  cam.setCameraID(0); // 2
  imageMode(CENTER);
  stroke(255);
  textSize(48); // 3
}

void draw() {
  image(cam, width/2, height/2, width, height);
  drawUI(); // 4
}

void drawUI() { // 1
  fill(0, 128);
  rect(0, 0, width/4, 100);
  rect(width/4, 0, width/4, 100);
  rect(2*(width/4), 0, width/4, 100);
  rect(3*(width/4), 0, width/4, 100);
  fill(255);
  if (cam.isStarted()) // 2
    text("stop", 20, 70);
  else
    text("start", 20, 70);
  text("camera", (width/4)+20, 70);
  text("flash", 2*(width/4)+20, 70);
}
void mousePressed() { // 3
  if (mouseY <= 100) { // 4
    if (mouseX > 0 && mouseX < width/4) { // 5
      if (cam.isStarted())
      {
        cam.stop();
      }
      else
      {
        if (!cam.start())
          println("Failed to start camera.");
      }
    }
    else if (mouseX > width/4 && mouseX < 2*(width/4)) // 6
    {
      int cameraID = 0;
      if (cam.getCameraID() == 0)
        cameraID = 1;
      else
        cameraID = 0;
      cam.stop();
      cam.setCameraID(cameraID);
      cam.start();
    }
    else if (mouseX >2*(width/4) && mouseX < 3*(width/4)) // 7
    {
      if (cam.isFlashEnabled()) // 8
        cam.disableFlash();
      else
        cam.enableFlash();
    }
  }
}
void onCameraPreviewEvent() {
  cam.read();
}
void exit() {
  cam.stop();
}

void logic(){
  if(mousePressed&&!mdown){
      mdown = true;
      counter++;
      println(counter);
    }
    
    if(!mousePressed)mdown = false;
    if(counter>6)counter = 0;
};

```

note this only works from pc build, not apde.

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [December 31, 2020, 4:33pm UTC](https://discourse.processing.org/t/open-android-camera/23696/11 "2020-12-31T16:33:29Z")

</div>

@paulgoux === and note that @noel codes with apde…

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [December 31, 2020, 4:40pm UTC](https://discourse.processing.org/t/open-android-camera/23696/12 "2020-12-31T16:40:48Z")

</div>

> [@akenaton](#):
>
> @paulgoux === ??? - Is this code running?

I assume he is referring to your code above I posted there, but it has your name referenced.
