Jump to content

Cannot get accelerometer callbacks to work in Android


kmp
 Share

Recommended Posts

Hi -

 

I've just written my first android game using the accelerometer. But it does not work. To be precise the callbacks in the following statement never get executed:

 

 this.watchID = navigator.accelerometer.watchAcceleration(this.onSuccess, this.onFailure, options);

 

I can trace the code into this statement and the statement executes without error, returning a valid watchID. However, the onSuccess and onFailure methods never get called. It's like my phone has no accelerometer or the accelerometer has been disabled.

 

I am using the cordova command-line tools.

 

I thought this was something to do with my code, so I created a new cordova project and used the example accelerometer code.

 

What I found was that in the emulator the callback for onFailure was called. I presume this is correct as the emulator has no accelerometer. However, when I transferred the example app to my phone, no callback - success or failure - was ever called.

 

So I don't think my code is at fault. Perhaps it is something to do with my phone. It is a Nexus 4 and has just been upgraded to the latest Android (lollipop). The API level of the game is 19.

 

Do I have to do something to enable the accelerometer on my phone? There must be something major I'm missing since I get something from the emulator but nothing from the actual phone.

 

Thanks in advance for any help.

 

Ken

 

 

 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...