Open Android Camera

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

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)

@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;

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(){
  
  
  
}
1 Like

@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

@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…

Ok i understood. Thanks for the clarification

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

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

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

if not this should get it working

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.

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

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