문제

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

}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top