How to disable vibration and sound when touched in android programmatically?

I am making one application and opening alertdialog using OnLongClickListener ImageView as well as ontouch scaling. But when I pressed for a long time, and not vibrating, you can turn off vibration on a long cliche. I am using the code below:

public OnLongClickListener longClick = new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { Vibrator vibe = (Vibrator)DailySatsangActivity.this.getSystemService(Context.VIBRATOR_SERVICE) ; vibe.cancel(); } }; 
+4
source share
2 answers

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

You can disable "Haptic Feedback" using the code below,

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

Java Method: setHapticFeedbackEnabled(boolean)

OR

You can use the Audio Manger class to mute sound and vibration, see the setRingerMode method of the Audio Manager class.

Example:

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

Hope this solves your problem.

+6
source

For this you must use the AudioManager class.

0
source

All Articles