FileDocCategorySizeDatePackage
Vibrator.javaAPI DocAndroid 1.5 API2512Wed May 06 22:41:56 BST 2009android.os

Vibrator

public class Vibrator extends Object
Class that operates the vibrator on the device.

If your process exits, any vibration you started with will stop.

Fields Summary
IHardwareService
mService
Constructors Summary
public Vibrator()

hide

        mService = IHardwareService.Stub.asInterface(
                ServiceManager.getService("hardware"));
    
Methods Summary
public voidcancel()
Turn the vibrator off.

        try {
            mService.cancelVibrate();
        } catch (RemoteException e) {
        }
    
public voidvibrate(long milliseconds)
Turn the vibrator on.

param
milliseconds How long to vibrate for.

        try {
            mService.vibrate(milliseconds);
        } catch (RemoteException e) {
        }
    
public voidvibrate(long[] pattern, int repeat)
Vibrate with a given pattern.

Pass in an array of ints that are the times at which to turn on or off the vibrator. The first one is how long to wait before turning it on, and then after that it alternates. If you want to repeat, pass the index into the pattern at which to start the repeat.

param
pattern an array of longs of times to turn the vibrator on or off.
param
repeat the index into pattern at which to repeat, or -1 if you don't want to repeat.

        // catch this here because the server will do nothing.  pattern may
        // not be null, let that be checked, because the server will drop it
        // anyway
        if (repeat < pattern.length) {
            try {
                mService.vibratePattern(pattern, repeat, new Binder());
            } catch (RemoteException e) {
            }
        } else {
            throw new ArrayIndexOutOfBoundsException();
        }