onAccuracyChanged,为什么呢? [英] onAccuracyChanged, why?
问题描述
这是自动生成的功能实现,当我得到一个
this is one of the auto-generated functions I get when implementing
SensorEventListener
SensorEventListener
我已经搜查,比这说明没有找到了:做的东西,如果传感器的精度变化
何时以及如何接近传感器的精度变化?
以及以何种方式可这是非常有用的我的应用程序?
i've searched and didn't find anymore than this description: "Do something if sensor accuracy changes." when and how does the proximity sensor accuracy changes ? and in what way can this be useful on my apps ?
推荐答案
据我的了解, OnAccuracyChanged
方法被调用时有不同的精度和<$ C传感器报告$ C> onSensorChanged 每当有传感器报告一个新值方法被调用。
According to my understanding, OnAccuracyChanged
method is invoked whenever a sensor reports with different accuracy and onSensorChanged
method is called whenever a sensor reports a new value.
我也曾经有过同样的问题,在如何利用 onAccuracyChanged
方法。
I too had the same question, as in how to make use of onAccuracyChanged
method.
假设你想要的传感器数据,只有当精度高,没有低于。做到这一点的方法之一是创建一个新的全局变量。在 onAccuracyChanged
方法,它初始化为某个值,并在 onSensorChanged
功能,增加一个的if..else
的条件。
Let's say you want the sensor data only when the accuracy is high,nothing below that. One way to do that is to create a new global variable. Inside the onAccuracyChanged
method, initialize it to some value, and inside onSensorChanged
function, add an if..else
condition.
样code:
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// Do something here if sensor accuracy changes.
// You must implement this callback in your code.
if (sensor == mValuen) {
switch (accuracy) {
case 0:
System.out.println("Unreliable");
con=0;
break;
case 1:
System.out.println("Low Accuracy");
con=0;
break;
case 2:
System.out.println("Medium Accuracy");
con=0;
break;
case 3:
System.out.println("High Accuracy");
con=1;
break;
}
}
}
现在使用的条件为如果(CON == 1)
做必要的修改。
Now use condition as if (con==1)
to do the required changes.
P.S。按照Android文档。
P.S. According to the android documentation.
public abstract void onAccuracyChanged (int sensor, int accuracy)
Called when the accuracy of a sensor has changed. See SensorManager for details.
Parameters
sensor The ID of the sensor being monitored
accuracy The new accuracy of this sensor.
所以每当精度变化,你将不得不这种变化的参考。
So whenever the accuracy changes,you will have a reference to that change.
请让我知道如果我失去了一些东西。
谢谢你。
Please let me know if am missing something. Thanks.
这篇关于onAccuracyChanged,为什么呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!