How to disable vibration and sound on touch in Android programmatically?

android

Solution

I think the problem you are facing is Haptic Feedback instead of the normal vibration.

You can turn-off "Haptic Feedback" by using below code,

XML attribute: `android:hapticFeedbackEnabled //set it true or false in view's xml file for the desired result.`

Java method: `setHapticFeedbackEnabled(boolean)`

OR

You can use Audio Manger class to disable sound and vibration, have a look at setRingerMode method of Audio Manager class.

Example :

AudioManager aManager=(AudioManager)getSystemService(AUDIO_SERVICE);
aManager.setRingerMode(aManager.RINGER_MODE_SILENT);

Hope this will solve your problem.

Problem

I am making one application and opening alertdialog using OnLongClickListener of ImageView and also ontouch zooming. But when I pressed long than vibrating on so is it possible to turn off vibrating on long click listener. I am using below code: ``` public OnLongClickListener longClick = new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { Vibrator vibe = (Vibrator)DailySatsangActivity.this.getSystemService(Context.VIBRATOR_SERVICE) ; vibe.cancel(); } }; ```

Original source