In my app, I\'d like to use the camera, if the device has one. Are there any devices running android that do not have a camera? By including the following into my m
I found in android tv boxes where you can plug and play usb camera a number of times. At some point of time, The camera service starts saying that it detected one camera in the system while no camera is connected to the system. This happens when you plug in/out the camera a number of times. To fix that, I found this solution working:
//under oncreate:
//cameraManager = ((CameraManager) getSystemService(Context.CAMERA_SERVICE));
public int getNumberOfCameras() {
int count_ = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
try {
count_ = cameraManager.getCameraIdList().length;
if(count_==1)
{
try {
cameraManager.getCameraCharacteristics(cameraManager.getCameraIdList()[0]);
}catch (Exception e)
{
count_ = 0;
}
}
} catch (Exception e) {
//e.printStackTrace();
}
}
else {
count_ = Camera.getNumberOfCameras();
}
return count_;
}