title: Flashlight apk version is Different?
body: <p>I have flashlight apk with two problem.
  İf I use camera, camera.params. My apk working with lower versions Android 5. THen if I use camera2 and camera.manager, My app working with Android 5 and higger versions.</p>
  
  <p>I wanna work with Android version 4 and higger, work with all versions.
  How can I do this?</p>
  
  <p>Pls help me for this, thanks.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>package com.hallac.erdogan.spechflash;
  
  import android.content.Context;
  import android.content.Intent;
  import android.content.pm.PackageManager;
  import android.hardware.Camera;
  import android.hardware.camera2.CameraAccessException;
  import android.hardware.camera2.CameraManager;
  import android.os.Build;
  import android.os.Bundle;
  import android.support.annotation.RequiresApi;
  import android.support.v7.app.AppCompatActivity;
  import android.util.Log;
  import android.view.View;
  import android.view.Window;
  import android.view.WindowManager;
  import android.widget.ImageButton;
  
  
  public class MainActivity extends AppCompatActivity {
  
      ImageButton btnSwitch;
      ImageButton flashlight;
  
      private Camera camera;
      private boolean isFlashOn;
      private boolean hasFlash;
      Camera.Parameters params;
      private CameraManager mCameraManager;
      private String mCameraId;
  
  
  
  
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          requestWindowFeature(Window.FEATURE_NO_TITLE);//full keran ile ilgili ayarlar
          getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,//full keran ile ilgili ayarlar
                  WindowManager.LayoutParams.FLAG_FULLSCREEN);//full keran ile ilgili ayarlar
  
  
          setContentView(R.layout.activity_main);
  
          // flash switch button
          btnSwitch = (ImageButton) findViewById(R.id.buton);
          flashlight=(ImageButton)findViewById(R.id.flashlight);
  
  
          // First check if device is supporting flashlight or not
          hasFlash = getApplicationContext().getPackageManager()
                  .hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
  
  
  
          // get the camera
          getCamera();
  
          // displaying button image
          toggleButtonImage();
  
  
          // Switch button click event to toggle flash on/off
          btnSwitch.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  if (isFlashOn) {
                      // turn off flash
                      turnOffFlash();
                  } else {
                      // turn on flash
                      turnOnFlash();
                  }
              }
          });
  
  
          flashlight.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
  
                  Intent intent= new Intent(getBaseContext(),SpeakNow.class);
                  startActivity(intent);
              }
          });
  
  
      }
  
  
      // Get the camera
      private void getCamera() {
          if (camera == null) {
              try {
                  camera = Camera.open();
                  params = camera.getParameters();
              } catch (RuntimeException e) {
  
              }
          }
      }
  
  
  
      private void turnOnFlash() {
          if (!isFlashOn) {
              if (camera == null || params == null) {
                  return;
              }
  
  
  
  
              params = camera.getParameters();
              params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
              camera.setParameters(params);
              camera.startPreview();
              isFlashOn = true;
              toggleButtonImage();
          }
  
      }
  
  
      private void turnOffFlash() {
          if (isFlashOn) {
              if (camera == null || params == null) {
                  return;
              }
  
              params = camera.getParameters();
              params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
              camera.setParameters(params);
              camera.stopPreview();
              isFlashOn = false;
              toggleButtonImage();
          }
      }
  
  
      private void toggleButtonImage(){
          if(isFlashOn){
              btnSwitch.setImageResource(R.drawable.light_on);
          }else{
              btnSwitch.setImageResource(R.drawable.light_off);
          }
      }
  
  
  
  
  
  
      @Override
      protected void onDestroy() {
          super.onDestroy();
      }
  
      @Override
      protected void onPause() {
          super.onPause();
  
          // on pause turn off the flash
          //  turnOffFlash();
      }
  
      @Override
      protected void onRestart() {
          super.onRestart();
      }
  
      @Override
      protected void onResume() {
          super.onResume();
  
          // on resume turn on the flash
          if(hasFlash)
              turnOnFlash();
      }
  
      @Override
      protected void onStart() {
          super.onStart();
  
          // on starting the app get the camera params
          getCamera();
      }
  
      @Override
      public void onBackPressed() {
          // TODO Auto-generated method stub
          super.onBackPressed();
  
          params = camera.getParameters();
          params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
          camera.setParameters(params);
          camera.stopPreview();
          isFlashOn = false;
  
          if (camera != null) {
              camera.release();
              camera = null;
          }
          Log.d("Camera","Back Pressed");
      }
  
      @Override
      protected void onStop() {
          super.onStop();
  
          // on stop release the camera
          //   if (camera != null) {
          //       camera.release();
          //      camera = null;
          // }
      }
  
  }</code></pre>
  </div>
  </div>
  </p>