如何避免 Android getSystemService(Context.SENSOR_SERVICE) 挂起模拟器?

发布于 2024-12-22 19:01:57 字数 289 浏览 1 评论 0原文

每当我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嘿看小鸭子会跑 2024-12-29 19:01:57

我在模拟器中遇到了与 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

尘世孤行 2024-12-29 19:01:57

我在使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文