title: Camera2 Api autoflash not work
body: <p>I needed to help with android camera 2 api automatic flash.
  This solution works on one phone but not on the other.
  I've spent a few hours searching for solutions, but I'm unsuccessful.</p>
  
  <p>My takePhoto code:</p>
  
  <pre><code>pictureTaken = false;
      if (null == cameraDevice) {
          Log.e(TAG, "cameraDevice is null");
          return;
      }
      CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
      try {
          int width = 1024;
          int height = 768;
          cv.setBackground(getResources().getDrawable(R.drawable.fotak_zeleny));
          ImageReader reader = ImageReader.newInstance(width, height, ImageFormat.JPEG, 1);
          List&lt;Surface&gt; outputSurfaces = new ArrayList&lt;Surface&gt;(2);
          outputSurfaces.add(reader.getSurface());
          outputSurfaces.add(new Surface(textureView.getSurfaceTexture()));
          final CaptureRequest.Builder captureBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
          captureBuilder.addTarget(reader.getSurface());
          captureBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
          captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_AUTO);
          captureBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CaptureRequest.CONTROL_AF_TRIGGER_START);
          if (flashMode == FLASH_AUTO) {
              captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
          } else if (flashMode == FLASH_ON) {
              captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH);
          } else if (flashMode == FLASH_OFF) {
              captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF);
          }
  
          // Orientation
          int rotation = getWindowManager().getDefaultDisplay().getRotation();
          captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation));
          final File file = new File(fileName);
          if (file.exists()) {
              file.delete();
          } 
  etc....
  </code></pre>
  
  <p>My create camera preview code:</p>
  
  <pre><code>protected void createCameraPreview() {
      try {
          SurfaceTexture texture = textureView.getSurfaceTexture();
          assert texture != null;
          texture.setDefaultBufferSize(imageDimension.getWidth(), imageDimension.getHeight());
          Surface surface = new Surface(texture);
          captureRequestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
          captureRequestBuilder.set(CaptureRequest.CONTROL_AE_LOCK, false);
  
          captureRequestBuilder.addTarget(surface);
          cameraDevice.createCaptureSession(Arrays.asList(surface), new CameraCaptureSession.StateCallback() {
              @Override
              public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
                  //The camera is already closed
                  if (null == cameraDevice) {
                      return;
                  }
                  // When the session is ready, we start displaying the preview.
                  cameraCaptureSessions = cameraCaptureSession;
                  updatePreview();
              }
  
              @Override
              public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) {
  
              }
          }, null);
      } catch (CameraAccessException e) {
          e.printStackTrace();
      } catch (NullPointerException ex) {
          ex.printStackTrace();
      }
  }
  </code></pre>
  
  <p>This solution work fine on my LG phone, but on alcatel not work. 
  I tried a lot of ideas that are written here, unsuccessfully.</p>
  
  <p>Can help me please?</p>
  
  <p>Big thanks</p>
  
  <p>(Sorry for my English)</p>