i am using the orientation sensor in the android app. I want to find out when the sensor value goes less than 100 second time. how to find it.
我在Android应用程序中使用方向传感器。我想知道传感器值何时小于100秒。怎么找到它。
public void onSensorChanged(SensorEvent event) {
// TODO Auto-generated method stub
if( event.sensor.getType() == Sensor.TYPE_ORIENTATION)
{
value= (event.values[0]);
if (value<100){
}
}}
1 个解决方案
#1
0
You can just keep of track of it in a class variable. I'm assuming that you just want to detect it going under 100 twice at any time, not twice consecutively.
您可以在类变量中跟踪它。我假设您只想在任何时间检测到它低于100,而不是连续两次。
public void onSensorChanged(SensorEvent event) {
if( event.sensor.getType() == Sensor.TYPE_ORIENTATION)
{
value= (event.values[0]);
if (value<100){
if (!lessThanBefore) //first time it is less than 100, mark
{
lessThanBefore= true;
}
else
{
//CONDITION DETECTED...
}
}
}}
#1
0
You can just keep of track of it in a class variable. I'm assuming that you just want to detect it going under 100 twice at any time, not twice consecutively.
您可以在类变量中跟踪它。我假设您只想在任何时间检测到它低于100,而不是连续两次。
public void onSensorChanged(SensorEvent event) {
if( event.sensor.getType() == Sensor.TYPE_ORIENTATION)
{
value= (event.values[0]);
if (value<100){
if (!lessThanBefore) //first time it is less than 100, mark
{
lessThanBefore= true;
}
else
{
//CONDITION DETECTED...
}
}
}}