我有创建方法来振动手机,代码运行良好,但我不能像“播放然后停止然后播放”那样振动。如何管理这种振动?
码
//@JavascriptInterface
public void Viber(String value )
{
// Get instance of Vibrator from current Context
Vibrator v = (Vibrator)mContext.getSystemService(mContext.VIBRATOR_SERVICE);
if (value.equals("on"))
{
// Vibrate for 300 milliseconds
v.vibrate(6000);
}
else
{
v.cancel();
}
}
答案 0 :(得分:1)
您必须创建一些模式,例如:
long pattern[] = {0,300,200,500,200,600,200,800};
第一个值是等待开始振动的时间,下一个是振动持续时间,第三个是暂停等等....
然后致电:
v.vibrate(pattern,-1);