}
ck_bright.setOnCheckedChangeListener(this);
tv_light = (TextView) findViewById(R.id.tv_light);
mSensroMgr = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
}
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (buttonView.getId() == R.id.ck_bright) {
SwitchUtil.setAutoBrightStatus(this, isChecked);
}
}
@Override
protected void onPause() {
super.onPause();
mSensroMgr.unregisterListener(this);
}
@Override
protected void onResume() {
super.onResume();
mSensroMgr.registerListener(this, mSensroMgr.getDefaultSensor(Sensor.TYPE_LIGHT),
SensorManager.SENSOR_DELAY_NORMAL);
}
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_LIGHT) {
float light_strength = event.values[0];
tv_light.setText(Utils.getNowDateTimeFormat() + "\n当前光线强度为" + light_strength);
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
//当传感器精度改变时回调该方法,一般无需处理
}
} android光线传感器开发(2):http://www.751com.cn/fanwen/lunwen_30827.html