opening a camera and viewing it live on surface view

  • Replies:0
  • OpenNot stickiedUnanswered
  • Forum posts: 2

May 23, 2016 9:27:48 PM via Website

am writing a program to start my back camera and see what the camera sees in a surfaceview. no photo taking or video recording. just the camera view when i start the app. I have to use the camera2 package.

copy pasted the syntaxes from android site. a complete is much welcome.

public class MainActivity extends AppCompatActivity {

private CameraDevice camera;
private CameraDevice.StateCallback callback;
private Handler handler;
private SurfaceView surfaceView;

protected void onCreate(Bundle savedInstanceState) {

public class cameraManager extends Object {
    CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);

public abstract class cameraDevice extends Object implements AutoCloseable{


class LooperThread extends Thread {

    public void run() {

        handler = new Handler() {
            public void handleMessage(Message msg) {
                // process incoming messages here


String cameraList[] = String[] getCameraIdList();
String cameraId = cameraList[0];

openCamera(cameraId, callback, handler);