0

I have implemented vibration using vibrator .In my application, when the user press the button, vibration works.For some users wont like vibration in app so i had a toggle button as vibration on/off. i just need to know how to implement the enable/disable the vibration function. this is my vibrator class

      Vibrator vib = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);  
     vib.vibrate(500);
      Toast.makeText(this, "vib started", Toast.LENGTH_LONG).show();
KMI
  • 496
  • 4
  • 24

1 Answers1

2

use boolean flag to toggle

if(isVibrate){
Vibrator vib = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);  
     vib.vibrate(500);
      Toast.makeText(this, "vib started", Toast.LENGTH_LONG).show();
}

else{

// do nothing

}
Ravi1187342
  • 1,247
  • 7
  • 14
  • 2
    You should also check the device audio status - don't vibrate if the user has their device on silent - AudioManager.getRingerMode() should return RINGER_MODE_VIBRATE or RINGER_MODE_NORMAL – Phil Haigh Jun 17 '13 at 08:52