Search code examples
androidimagecameracaptureandroid-camera2

How to show camera preview in Activity?


I came across many solutions on how to preview camera in Activity. But, they all use the deprecated hardware.camera for display.

How to do this using camera2? Any example for this available?


Solution

  • Your natural starting point would be the overview here and set of code samples here. The Camera2Basic samples include code that you wouldn't need if you only want a preview (for example it also contains code necessary for saving a still image). However, I'd recommend starting there and then removing any code that you don't need for your particular purposes.