Android SensorManager中的getSensorList()与getDefaultSensor() [英] getSensorList() vs. getDefaultSensor() in Android SensorManager

查看:1125
本文介绍了Android SensorManager中的getSensorList()与getDefaultSensor()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Android编写游戏,希望能够使用加速度计进行输入.

I'm writing a game for Android and want to be able to use the accelerometer for input.

我看到两种获取传感器的方法,一种方法是使用SensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER)的第一个元素,另一种方法是SensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER).

I see two ways of getting a sensor, one way is to use the first element of SensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER) and the other is SensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER).

getDefaultSensor文档说它可能会返回一个复合"传感器,所以如果我想要一个原始"传感器,则应使用getSensorList.

您知道复合传感器或原始传感器之间的区别是什么吗?这甚至适用于加速度计吗?有人对包含多个或复合加速度计的设备有经验吗? (或其他传感器?)

Any idea what the difference between a composite or raw sensor is? Does this even apply to the accelerometer? Anyone have experience with devices that contain multiple or composite accelerometers? (Or some other sensor?)

推荐答案

在这里,Google的文档要比其实现要先进得多.我浏览了代码存储库(似乎是2.3.1版本的源代码)并找到:

Google's documentation is way ahead of their implementation here. I browsed through the code repository (which seems to be 2.3.1-ish source) and found:

public Sensor getDefaultSensor(int type) {
    // TODO: need to be smarter, for now, just return the 1st sensor
    List<Sensor> l = getSensorList(type);
    return l.isEmpty() ? null : l.get(0);
}

因此,从getDefaultSensor()getSensorList()返回的传感器之间没有真正的区别(我不认为它们以后可以真正添加一个).

So there is no real difference (and I don't think they can really add one later) between the sensors returned from getDefaultSensor() and from getSensorList().

这篇关于Android SensorManager中的getSensorList()与getDefaultSensor()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆