Hi i am using Camera
api for showing preview on TextureView
. Now i need a functionality in which if user brings phone to low light surroundings or view with low exposure then camera sensor should automatically detect low light condition and turn on flash while previewing.
I tried below code for detecting sensor light and turns on/off light according to lux value i got in callback -
// Obtain references to the SensorManager and the Light Sensor
mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
mLightSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
// Implement a listener to receive updates
SensorEventListener listener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
mLightQuantity = event.values[0];
// ON/OFF flash according to mLightQuantity
}
}
// Register the listener with the light sensor -- choosing
// one of the SensorManager.SENSOR_DELAY_* constants.
mSensorManager.registerListener(
listener, lightSensor, SensorManager.SENSOR_DELAY_UI);
But above code detect light from TYPE_LIGHT
sensor which is present near speaker with front camera . This detects only light conditions in front of phone, but not with back camera . In short i want Auto Flash feature of Camera (which works on takePicture
) to work while previewing .