Android 手机震动控制

  • 让手机震动,需要创建Vibrator对象,通过调用vibrate方法来达到震动的目的。

    java.lang.Object

       ↳android.os.Vibrator

void

cancel()

Turn the vibrator off.

boolean

hasVibrator()

Check whether the hardware has a vibrator.

void

vibrate(long[] pattern, int repeat)

Vibrate with a given pattern.

void

vibrate(long milliseconds)

Turn the vibrator on.

 

  • 在Vibrate的参数中:

    pattern:  an array of longs of times for which to turn the vibrator on or off.

    repeat:  the index into pattern at which to repeat, or -1 if you don't want to repeat.

  • 特别需要注意的是,在new long[]{num0,num1,num2,...}中第0、2、4...个数代表不震动的时间(ms),而奇数标号上的数代表震动的时间(ms),这样便组成了一组震动方式(pattern)

  • 且,当repeat 为 0时, 持续震动。-1时,只震动一轮。

   1: mVibrator01 = ( Vibrator )getApplication().getSystemService( Service .VIBRATOR_SERVICE );
   2: /*设定震动的周期*/
   3: mVibrator01.vibrate( new long[]{100,10,100,1000},-1); 
   4: /*用Toast显示震动启动*/ 
   5: Toast.makeText(EX05_06.this, getString(R.string.str_ok) ,Toast.LENGTH_SHORT).show();
   6: /*取消震动*/ 
   7: mVibrator01.cancel(); 
   8: /*用Toast显示震动取消*/ 
   9: Toast.makeText(EX05_06.this, getString(R.string.str_end) ,Toast.LENGTH_SHORT).show();
  10:           

转载于:https://www.cnblogs.com/reaver21/archive/2011/09/17/2179700.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值