I work with Camera2API and I need to turn off the ability to take photos if there is not enough light outside ...

I've thought that when using a standard camera, then there is an opportunity to set the auto mode to flash.

If I understand correctly, the camera works with some kind of sensor that determines the amount of light and if it is not enough then the flash works.

How to connect to this sensor?

    1 answer 1

    In the end, I took advantage of this off article

    And did so

     public class SensorActivity extends Activity implements SensorEventListener { private SensorManager mSensorManager; private Sensor mPressure; @Override public final void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // Get an instance of the sensor service, and use that to get an instance of // a particular sensor. mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mLight= mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); } @Override public final void onAccuracyChanged(Sensor sensor, int accuracy) { // Do something here if sensor accuracy changes. } @Override public final void onSensorChanged(SensorEvent event) { float luminosity = event.values[0]; // Do something with this sensor data. } @Override protected void onResume() { // Register a listener for the sensor. super.onResume(); mSensorManager.registerListener(this, mLight, SensorManager.SENSOR_DELAY_NORMAL); } @Override protected void onPause() { // Be sure to unregister the sensor when the activity pauses. super.onPause(); mSensorManager.unregisterListener(this); } }