opening a camera and viewing it live on surface view

  • Replies:0
Uttaran Wary
  • 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;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

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() {
        Looper.prepare();

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

        Looper.loop();
    }
}

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

openCamera(cameraId, callback, handler);

onOpened(cameraId){

}

}

Reply