Sign in to follow this  

Cannot get accelerometer callbacks to work in Android

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.







Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.