Getting ready to use the camera

Before using the camera, we have to detect it and make sure it is connected to the Android Things board. For this purpose, we will use the CameraManager class:

  1. In AndroidCamera.java let us create a new method called initCamera().

 

  1. In this method, we first get the reference to the camera manager and then the app enumerates all the connected cameras:
        cManager = (CameraManager)         ctx.getSystemService(Context.CAMERA_SERVICE);            try {            String[] idCams = cManager.getCameraIdList();            camId = idCams[0];            }           catch (CameraAccessException e) {            e.printStackTrace();           }

In this project, we will use the first camera detected (as you can notice we use 0 as index).

  1. Moreover, in this method, we have to initialize an image container ...

Get Android Things Projects now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.