tags:

views:

300

answers:

2

If you want a button to provide haptic feedback (ie, the phone vibrates very briefly so you can feel that you really pushed the button), what's the standard way to do that? It seems you can either explicitly set an onClick() event and call the vibrate() function, giving a number of milliseconds to vibrate, or you can set hapticFeedbackEnabled in the view.

The documentation seems to indicate that the latter only works for long-presses or virtual on-screen keys: http://developer.android.com/reference/android/view/View.html#performHapticFeedback(int)

If that's right, then I need to either make my button a virtual on-screen key or manually set the onClick() event.

What do you recommend?

Also, if I want the vibrating to happen immediately when the user's finger touches the button, as opposed to when their finger "releases" the button, what's the best way to accomplish that?

Related question: http://stackoverflow.com/questions/2228151/how-to-enable-haptic-feedback-on-button-view

A: 

I think that calling vibrate() manually is not a good idea. It would mean someone who doesn't want haptic feedback will have his phone vibrating. Plus I don't know how it reacts on non-vibrating products. setHapticFeedbackEnabled is definitely the good way to do it; the method was created for this very specific purpopse.

Moons
Thanks Moons. Check out my comment on Edward's answer.
dreeves
+1  A: 

I use vibrate() in my calculator app, but that was only because the system had no haptic feedback options when I wrote it. I don't recommend that approach for a number of reasons. In particular, every phone has different characteristics (mass, vibrator motor, motor position, etc.) so what "feels" right on one phone won't be right on another.

However, it's fair to assume that the individual phone manufacturers have done at least a little "tuning" on their particular products, so the built-in haptic feedback has a better chance of feeling right across the board.

Additionally, as pointed out above, if you implement your own haptic feedback, you'll need to implement your own setting for it in your preferences. Far better to let the user set it on a system-wide basis.

Time permitting (hah!) I plan to switch from using vibrate() to using the system's built-in haptic feedback.

Edward Falk
Thanks Edward. I'm still unclear how this is actually done. For example, how do you make your buttons "virtual on-screen keys" and am I correct that that's the only way to to get haptic feedback on normal (not long-press) button presses?
dreeves
Looking at my source code, I see that I didn't do anything clever. All of my buttons call back to the same function, which starts with if( keyclick Where "vibrator" was obtained from vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);Ahhh, I see what you're getting at. You want this to work for Button widgets and the documentation implies that it's only for virtual keyboards. Sorry, haven't experimented with that.
Edward Falk