@Override publicvoidonReceive(Context context, Intent intent){ // Disable camera-related activities if there is no camera. boolean needCameraActivity = CHECK_BACK_CAMERA_ONLY ? hasBackCamera() : hasCamera();
if (!needCameraActivity) { Log.i(TAG, "disable all camera activities"); for (int i = 0; i < ACTIVITIES.length; i++) { disableComponent(context, ACTIVITIES[i]); } }
// Disable this receiver so it won't run again. disableComponent(context, "com.android.camera.DisableCameraReceiver"); }
private boolean hasCamera() { int n = android.hardware.Camera.getNumberOfCameras(); Log.i(TAG, "number of camera: " + n); return (n > 0); }
private boolean hasBackCamera() { int n = android.hardware.Camera.getNumberOfCameras(); CameraInfo info = new CameraInfo(); for (int i = 0; i < n; i++) { android.hardware.Camera.getCameraInfo(i, info); if (info.facing == CameraInfo.CAMERA_FACING_BACK) { Log.i(TAG, "back camera found: " + i); returntrue; } } Log.i(TAG, "no back camera"); returnfalse; }
/** * Returns the number of physical cameras available on this device. * * @return total number of accessible camera devices, or 0 if there are no * cameras or an error was encountered enumerating them. */ publicnativestaticintgetNumberOfCameras();