启用/ android系统中关闭振动功能? [英] Enable/disable vibration function in android?

查看:207
本文介绍了启用/ android系统中关闭振动功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用振动器。在我的应用程序,实现振动时PSS此按钮,用户$ P $,振动works.For一些用户不会像振动的应用程序,所以我有一个切换按钮振动开/关。 我只需要知道如何实现开启/关闭震动功能。 这是我的振动器类

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

解决方案

使用布尔标志来切换

 如果(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

}

这篇关于启用/ android系统中关闭振动功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆