且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

启用/ android系统中关闭振动功能?

更新时间:2023-02-26 21:27:06

使用布尔标志来切换

 如果(isVibrate){
振动器VIB =(震动)getSystemService(Context.VIBRATOR_SERVICE);
     vib.vibrate(500);
      Toast.makeText(这一点,VIB开始,Toast.LENGTH_LONG).show();
}

其他{

// 没做什么

}
 

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();

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

}