title: CameraManager on devices running lower than Lollipop
body: <p>I am facing a problem where I am using both the Camera (lower than Lollipop devices) and CameraManager class (Lollipop and above devices).</p>
  
  <p>The devices that run lower than Lollipop crashes, I believe this is because of the</p>
  
  <pre><code>import android.hardware.camera2.CameraManager;
  </code></pre>
  
  <p>part.
  How can I make this</p>
  
  <pre><code>package com.example.DeviceCommands;
  
  import android.annotation.TargetApi;
  import android.content.Context;
  import android.content.pm.PackageManager;
  import android.hardware.Camera;
  import android.hardware.Camera.AutoFocusCallback;
  import android.hardware.Camera.Parameters;
  import android.hardware.camera2.CameraAccessException;
  import android.hardware.camera2.CameraManager;
  import android.os.Build;
  
  public class FlashController
  {
      Context _context;
      boolean _is_supported = false;
      boolean _enabled = false;
      Object _camera;
  
      @TargetApi(Build.VERSION_CODES.L) public FlashController(Context context)
      {
          if (context.getPackageManager().hasSystemFeature(PackageManager
              .FEATURE_CAMERA_FLASH))
          {
              _context = context;
              _is_supported = true;
  
              if (android.os.Build.VERSION.SDK_INT &lt; android.os.Build.VERSION_CODES.LOLLIPOP)
              {
                  Camera camera = Camera.open();
  
                  if (camera == null)
                  {
                      _is_supported = false;
                      System.out.println("NOT SUPPORTED!");
                      return;
                  }
  
                  _camera = camera;
              }
              else
              {
                  CameraManager camera = (CameraManager) _context.getSystemService(Context.CAMERA_SERVICE);
                  _camera = camera;
              }
          }
      }
  
  
      @TargetApi(Build.VERSION_CODES.L) public void enableFlashLight()
      {
          if (android.os.Build.VERSION.SDK_INT &lt; android.os.Build.VERSION_CODES.LOLLIPOP)
          {
              Camera camera = (Camera) _camera;
              Camera.Parameters parameters = camera.getParameters();
  
              if(!parameters.getFlashMode().equals(android.hardware
                                          .Camera.Parameters.FLASH_MODE_TORCH)
                                          &amp;&amp; !_enabled)
              {  
                  Parameters params = camera.getParameters();
                  params.setFlashMode(Parameters.FLASH_MODE_TORCH);
                  camera.setParameters(params);
                  camera.startPreview();
                  _enabled = true;
                  camera.autoFocus(new AutoFocusCallback()
                  {
                      public void onAutoFocus(boolean success, Camera camera)
                      {
  
                      }
                  });
              }
          }
          else
          {
              //CameraManager manager =(CameraManager) _context.getSystemService(Context.CAMERA_SERVICE);
  
              try
              {
                  CameraManager camera = (CameraManager) _camera;
  
                  for(int i = 0; i &lt; camera.getCameraIdList().length; i++)
                  {
                      System.out.println("Camera=" + camera.getCameraCharacteristics(
                                                     camera.getCameraIdList()[i]));
                  }
              }
              catch (CameraAccessException e)
              {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
          }
      }
  
      public void disableFlashLight()
      {
          if (android.os.Build.VERSION.SDK_INT &lt; android.os.Build.VERSION_CODES.LOLLIPOP)
          {
              Camera cam = Camera.open();
              Camera.Parameters parameters = cam.getParameters();
  
              if(parameters.getFlashMode().equals(android.hardware
                                          .Camera.Parameters.FLASH_MODE_TORCH))
              {
                  parameters.setFlashMode(Parameters.FLASH_MODE_OFF);
                  cam.setParameters(parameters);
                  cam.release();
              }
  
          }
      }   
  
  }
  </code></pre>
  
  <p>work if the <code>import</code> part will make devices running lower than Lollipop crash?</p>
  
  <p>Thanks for any help and advice!</p>
  
  <p>EDIT:
  Added the whole class above.
  Logcat output</p>
  
  <pre><code>06-09 19:44:30.219: E/ViewRootImpl(956): sendUserActionEvent() mView == null
  06-09 19:44:31.360: E/dalvikvm(956): Could not find class 'android.hardware.camera2.CameraManager', referenced from method com.example.DeviceCommands.FlashController.&lt;init&gt;
  06-09 19:44:31.360: W/dalvikvm(956): VFY: unable to resolve check-cast 122 (Landroid/hardware/camera2/CameraManager;) in Lcom/example/DeviceCommands/FlashController;
  06-09 19:44:31.360: D/dalvikvm(956): VFY: replacing opcode 0x1f at 0x003a
  06-09 19:44:31.367: E/dalvikvm(956): Could not find class 'android.hardware.camera2.CameraManager', referenced from method com.example.DeviceCommands.FlashController.enableFlashLight
  06-09 19:44:31.367: W/dalvikvm(956): VFY: unable to resolve check-cast 122 (Landroid/hardware/camera2/CameraManager;) in Lcom/example/DeviceCommands/FlashController;
  06-09 19:44:31.367: D/dalvikvm(956): VFY: replacing opcode 0x1f at 0x0040
  06-09 19:44:31.367: W/dalvikvm(956): VFY: unable to resolve exception class 120 (Landroid/hardware/camera2/CameraAccessException;)
  06-09 19:44:31.367: W/dalvikvm(956): VFY: unable to find exception handler at addr 0x6b
  06-09 19:44:31.367: W/dalvikvm(956): VFY:  rejected Lcom/example/DeviceCommands/FlashController;.enableFlashLight ()V
  06-09 19:44:31.367: W/dalvikvm(956): VFY:  rejecting opcode 0x0d at 0x006b
  06-09 19:44:31.367: W/dalvikvm(956): VFY:  rejected Lcom/example/DeviceCommands/FlashController;.enableFlashLight ()V
  06-09 19:44:31.367: W/dalvikvm(956): Verifier rejected class Lcom/example/DeviceCommands/FlashController;
  06-09 19:44:31.367: D/AndroidRuntime(956): Shutting down VM
  06-09 19:44:31.367: W/dalvikvm(956): threadid=1: thread exiting with uncaught exception (group=0x4100d930)
  06-09 19:44:31.375: E/AndroidRuntime(956): FATAL EXCEPTION: main
  06-09 19:44:31.375: E/AndroidRuntime(956): java.lang.VerifyError: com/example/DeviceCommands/FlashController
  06-09 19:44:31.375: E/AndroidRuntime(956):  at com.example.babymonitorer.MainActivity.onClick(MainActivity.java:121)
  06-09 19:44:31.375: E/AndroidRuntime(956):  at android.view.View.performClick(View.java:4421)
  06-09 19:44:31.375: E/AndroidRuntime(956):  at android.view.View$PerformClick.run(View.java:18190)
  06-09 19:44:31.375: E/AndroidRuntime(956):  at android.os.Handler.handleCallback(Handler.java:725)
  06-09 19:44:31.375: E/AndroidRuntime(956):  at android.os.Handler.dispatchMessage(Handler.java:92)
  06-09 19:44:31.375: E/AndroidRuntime(956):  at android.os.Looper.loop(Looper.java:175)
  06-09 19:44:31.375: E/AndroidRuntime(956):  at android.app.ActivityThread.main(ActivityThread.java:5279)
  06-09 19:44:31.375: E/AndroidRuntime(956):  at java.lang.reflect.Method.invokeNative(Native Method)
  06-09 19:44:31.375: E/AndroidRuntime(956):  at java.lang.reflect.Method.invoke(Method.java:511)
  06-09 19:44:31.375: E/AndroidRuntime(956):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
  06-09 19:44:31.375: E/AndroidRuntime(956):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
  06-09 19:44:31.375: E/AndroidRuntime(956):  at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>MainActivity line 121: <code>FlashController fc = new FlashController(this);</code></p>