-->

启用/ android系统中禁用振动功能?(Enable/disable vibration fun

2019-06-23 10:26发布

我已经实现振动使用振动器。在我的应用程序,当用户按下按钮,振动works.For一些用户不会喜欢在应用振动,所以我有一个切换按钮上振动/关。 我只需要知道如何实现的启用/禁用震动功能。 这是我的振动器类

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

Answer 1:

使用布尔标志切换

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

else{

// do nothing

}


文章来源: Enable/disable vibration function in android?