【问题标题】:how to manage mobile vibration?如何管理手机震动?
【发布时间】:2013-06-26 11:11:07
【问题描述】:

我已经创建了振动手机的方法,代码运行良好,但我不能像“播放然后停止然后播放”那样振动。如何管理这种类型的振动?

代码

 //@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();
        }
    }

【问题讨论】:

  • 你试过android api demos vibrator sample吗?

标签: android eclipse vibration android-vibration


【解决方案1】:

你必须创建一些模式,例如:

   long pattern[]  = {0,300,200,500,200,600,200,800};

第一个值是等待开始振动的时间,第二个是振动持续时间,第三个是暂停等等......

然后调用:

   v.vibrate(pattern,-1);

【讨论】:

  • 我遇到了这个错误 Vibrator 类型中的方法 vibrate(long[], int) 不适用于参数 (int[], int)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多