6
所以我正在寻找一种方法来获取光传感器的当前值(显然在勒克斯)按下按钮。下面是我使用来实现光传感器的控制代码获取光传感器值
public class SensorActivity extends Activity implements SensorEventListener
{
private final SensorManager mSensorManager;
private final Sensor mLight;
int minLux = 0;
int currentLux = 0;
int maxLux;
public SensorActivity()
{
mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
mLight = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
}
protected void onResume()
{
super.onResume();
mSensorManager.registerListener((SensorEventListener) this, mLight, SensorManager.SENSOR_DELAY_NORMAL);
}
protected void onPause()
{
super.onPause();
mSensorManager.unregisterListener((SensorListener) this);
}
public void onAccuracyChanged(Sensor sensor, int accuracy)
{
if(sensor.getType() == Sensor.TYPE_LIGHT)
{
}
}
public void onSensorChanged(SensorEvent event)
{
if(event.sensor.getType() == Sensor.TYPE_LIGHT)
{
}
}
}
我也有这样的代码使按钮来调用一个函数
<Button android:layout_width="122px" android:id="@+id/widget35" android:text="Start" android:layout_height="wrap_content" android:layout_x="112dp" android:layout_y="249dp" android:onClick="onButtonDown"></Button>
如何将获得当前的流明值,而该应用程序正在后台运行,并且如何获取当前勒克斯值并将其存储在按钮按下int maxLux;
?
感谢您的帮助!只有当它发生变化时,我才需要一个常数值。我对你的代码做了一些调整。 'maxLux'将是基于原始校准的常量(按下哪个按钮),则屏幕的亮度将根据'maxLux'中currentLux的百分比而改变 – Cistoran