Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Disable default vibration of OnLongClick

Tags:

android

Is there a way to disable the vibration for the OnLongClick event?

I want no vibration or if enabled a custom vibration.

EDIT: Thank you that did it!

like image 284
Markus1189 Avatar asked Jan 12 '11 14:01

Markus1189


1 Answers

Sure. If you look in the base View class, there are several options for haptic feedback, such as:

A boolean XML attribute: android:hapticFeedbackEnabled
and its related Java method: setHapticFeedbackEnabled(boolean)

There are other related methods such as performHapticFeedback() that you can call, but if you've disabled haptic feedback in the View, you'll have to pass a flag to override the View's setting, and perform it anyway. There are some constants you can pass, located in HapticFeedbackConstants, to get different vibration patterns from the system. To do a custom one, you'd have to override your onLongClick method and get an instance of the VIBRATOR service and have it perform a custom vibration pattern from there.

like image 147
Kevin Coppock Avatar answered Sep 23 '22 04:09

Kevin Coppock