Class Overview
设备上的振动器控制类
如果你的进程退出,你将会停止任何设置了的震动
获得系统振动器的一个实例,调用getSystemService(String)
VIBRATOR_SERVICE
为参数
Summary
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
abstract void |
cancel()
Turn the vibrator off. 关闭震动器 | ||||||||||
abstract boolean |
hasVibrator()
Check whether the hardware has a vibrator.
检查硬件是否有一个振动器。
| ||||||||||
abstract void |
vibrate(long[] pattern, int repeat)
Vibrate with a given pattern.
振动的模式
| ||||||||||
abstract void |
vibrate(long milliseconds)
Vibrate constantly for the specified period of time.
指定震动的时间长度。
|
[Expand]
Inherited Methods
| |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Object
|
Public Methods
public abstract void cancel ()
Turn the vibrator off.
关掉振动器。
This method 。requires the caller to hold the permission VIBRATE
.
这种方法要求调用方允许振动。
public abstract boolean hasVibrator ()
Check whether the hardware has a vibrator.
检查硬件是否有一个振动器。
Returns
- True if the hardware has a vibrator, else false.
public abstract void vibrate (long[] pattern, int repeat)
Vibrate with a given pattern.
设置震动的模式
Pass in an array of ints that are the durations for which to turn on or off the vibrator in milliseconds. The first value indicates the number of milliseconds to wait before turning the vibrator on. The next value indicates the number of milliseconds for which to keep the vibrator on before turning it off. Subsequent values alternate between durations in milliseconds to turn the vibrator off or to turn the vibrator on.
To cause the pattern to repeat, pass the index into the pattern array at which to start the repeat, or -1 to disable repeating.
This method requires the caller to hold the permission VIBRATE
.
传入的整数数组的持续时间来打开或关闭振动器,以毫秒为单位。第一个值表示将振动器之前等待的毫秒数。下一个值表示震动的毫秒数,之后振动器将其关闭。随后值之间的交替时间以毫秒为单位,关掉振动器或启动振动器。
Parameters
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. |
public abstract void vibrate (long milliseconds)
Vibrate constantly for the specified period of time.
在指定的时间内不断的震动
This method requires the caller to hold the permission VIBRATE
.
这种方法要求调用方允许振动。
Parameters
milliseconds | The number of milliseconds to vibrate. |
---|
获取方式
(Vibrator) getSystemService(VIBRATOR_SERVICE);
需要权限
<uses-permission android:name="android.permission.VIBRATE"/>