How to avoid Android getSystemService(Context.SENSOR_SERVICE) hanging emulator?

隐身守侯 提交于 2019-12-18 15:17:25

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/8626718/how-to-avoid-android-getsystemservicecontext-sensor-service-hanging-emulator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!