如何避免 Android getSystemService(Context.SENSOR_SERVICE) 挂起模拟器?
每当我在 Android 模拟器中调用此方法时:
SensorManager sensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
模拟器挂起。在搜索这个问题时,我发现很多参考资料早在 2009 年就已修复,但我目前使用的是当前可用的最新 SDK/工具(2011 年 12 月)。 API 级别 8/v2.2。
我是否必须真正实现代码来检查我是否在模拟器中运行并避免所有基于传感器的代码?
Whenever I call this method in the Android emulator:
SensorManager sensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
The emulator hangs. When searching for this problem, I find a lot of references of this being fixed back in 2009, but I'm currently using the latest SDK/Tools available at the current time (Dec 2011). API level 8 / v2.2.
Must I really implement code for checking if I run in the emulator and avoid all sensor based code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在模拟器中遇到了与 API7 类似的情况:上述代码导致模拟器立即退出程序,没有任何警告或日志消息。 (API4和API10都可以;我没有专门测试API8)。
我通过在 AVD 设置中将加速度计设置为 false 解决了这个问题。 (我尝试这样做是因为 API14/API15 中的加速度计从快照启动时出现问题。)
此致,
Arjan
I experienced something similar with API7 in the emulator: the mentioned code causes the emulator to quit the program immediatly without any warning or log message. (API4 & API10 are ok; I did not test API8 specifically).
I have solved it by setting accelerometer to false in the AVD settings. (I tried this because of issues with the accelerometer in API14/API15 with launch from snapshot.)
Regards,
Arjan
我在使用 SDK r16(2011 年 12 月)时也遇到了同样的问题,关闭加速度计和磁场也没有帮助。
所以最后我重新创建了 AVD 并关闭了 avd 属性中的 3 项内容:加速度计、磁场和方向。现在效果很好。
I had the same issue with SDK r16 (Dec 2011), turning off accelerometer and magnetic field did not help.
So finally I recreated AVD and turned off 3 things in avd properties: Accelerometer, Magnetic field and Orientation. Now it works good.