Camera camera = Camera.open(); SurfaceTexture surfaceTexture = new SurfaceTexture(0); camera.setPreviewTexture(surfaceTexture); camera.startPreview();In this example, we first open the camera using the Camera.open() method. Then we create a new SurfaceTexture instance and pass it as a parameter to the setPreviewTexture() method. Finally, we start the camera preview using the camera.startPreview() method. This code can be placed inside a custom view or texture window to display the live camera preview in that window. The package library used for this method is android.hardware.