如何从Android相机获得亮度级别

时间:2015-07-14 12:47:45

标签: android camera android-sensors brightness

我想从Android相机获得亮度等级。

我需要显示Android相机检测到的亮度,是否有可能做到这一点?

1 个答案:

答案 0 :(得分:0)

private final SensorManager mSensorManager;
private final Sensor mLightSensor;
private float mLightQuantity;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Obtain references to the SensorManager and the Light Sensor 
    sensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
    lightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);

    // Implement a listener to receive updates 
    SensorEventListener listener = new SensorEventListener() {
        @Override 
        public void onSensorChanged(SensorEvent event) {
            lightQuantity = event.values[0];
        } 
    } 

    // Register the listener with the light sensor -- choosing 
    // one of the SensorManager.SENSOR_DELAY_* constants. 
    sensorManager.registerListener( 
            listener, lightSensor, SensorManager.SENSOR_DELAY_UI);
}