We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3183

Summary: Android vibration not being found as haptic device
Product: SDL Reporter: Jade Macho <nuda1998>
Component: hapticAssignee: Sylvain <sylvain.becker>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: enhancement    
Priority: P2 CC: martin.gerhardy, philipp.wiesemann
Version: HG 2.1   
Hardware: All   
OS: Android (All)   
Attachments: Sample code to call the Android Vibrator.

Description Jade Macho 2015-11-19 17:15:58 UTC
Created attachment 2309 [details]
Sample code to call the Android Vibrator.

Some Android devices, if not all phones, support vibration. It would be nice to access the vibration via SDL just like any other haptic device (similarly to how the accelerometer is being handled as joystick).

I've attached some example code to call the Vibrator. It is (as far as I know) only accessible via JNI and with the activity context (mSingleton in SDLActivity if I understood correctly).

I don't feel experienced enough to mimic the implementation of the accelerator as joystick and _not_ screw up everything (f.e. I don't know what SDL_HapticQuery should return). I'll at least test any related changes when / if available.

This is my first bug report here (this isn't a bug, but I've been linked to submit this here) so I'm sorry if this is not where it belongs or doesn't contain enough information.
Comment 1 Jade Macho 2015-11-19 19:52:10 UTC
I knew that I would screw something up.
Clarification and addition to my previous comment:

With "accessible via JNI" I meant "you must call Java code via the JNI environment", not "you must call native code to make the device vibrate", but that should be clear from the sample code.

Something I completely forgot to mention is that to use Vibrator, the app requires the VIBRATE permission in its manifest. I don't know how much of an issue this is for SDL.
Comment 2 Philipp Wiesemann 2015-12-03 22:01:36 UTC
See also the (later) bug 3191.
Comment 3 Martin Gerhardy 2015-12-06 11:51:39 UTC
If this gets applied. Please check whether the cmake support for android is already part of the CMAkeLists.txt and make sure that the haptic stuff is also supported then from within the cmake file.
Comment 4 Sam Lantinga 2017-08-14 04:21:59 UTC
There is a related patch in bug 3191
Comment 5 Sam Lantinga 2017-09-04 20:42:26 UTC
This is now implemented, thanks!