Sign in to follow this  

SDL2 Android accelerometer

Recommended Posts

Hi everyone,


So, I've been writing my own little SDL2/Open GL ES 2 engine/framework for a while now and making some good encouraging progress, particularly getting it to work on Android (via NDK) with touch support.  However, accessing the accelerometer is proving to be a bit of a show-stopper so was hoping someone with similar experiences can help me out.  The SDL2 'wishlist' suggests implementing official accelerometer support in the future leaving only workarounds and hacks for the moment it seems.   I've looked around on google and there are two solutions : 


1) Set the SDL_HINT_ACCELEROMETER_AS_JOYSTICK hint and then access Joystick number 0 as the x/y values of the accelerometer.  Compiles but does nothing.  The SDL2 wiki only directly mentions supporting this feature in iOS and NOT Android so perhaps it shouldn't even work?


2) Try to access the Accelerometer values directly using the Android_JNI_GetAccelerometerValues function.  However, I can't get this to compile since it complains with repeated definitions (no compile guards??) when including the required header (SDL2/src/core/android/SDL_android.h).  I tried hacking it myself but not to no avail.


Maybe there's something special/extra-hacky that needs to be done to get one of these to work, or perhaps someone knows a third 'better' way??  If you know one of these really should work and need me to post extra stuff (some compiler errors) then I can do so.  Thanks in advance for your help.

Share this post

Link to post
Share on other sites

ok, more than a 1000 views (apparently) and no replies so guess I'm out of luck!  :-/   


No worries, I'll maybe post on the SDL forum and hope someone can help me there (surely right? :-) ).  But if someone reads this late and can help, I would still appreciate the advice.


Thanks anyway!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this