10

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?

Magnus Johansson
  • 28,010
  • 19
  • 106
  • 164
  • 1
    Can the person who down-voted care to explain? – Magnus Johansson Dec 24 '11 at 21:01
  • This seems to only happen for me using API 8. Other APIs that I have tested (10, 15, 16) worked just fine. Obviously this is not an answer, just another tidbit of information. I'd LOVE an answer! Anyone, anyone? Bueller? – SMBiggs Jul 23 '14 at 04:49

2 Answers2

4

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

Arjan Mels
  • 279
  • 1
  • 3
  • 11
  • I needed to set in AVD settings: accelerometer to off and magnetic field to off. Now it works. – gw0 Jan 31 '12 at 11:28
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.

Osman-pasha
  • 634
  • 8
  • 18