FileDocCategorySizeDatePackage
SystemVibrator.javaAPI DocAndroid 5.1 API3445Thu Mar 12 22:22:10 GMT 2015android.os

SystemVibrator

public class SystemVibrator extends Vibrator
Vibrator implementation that controls the main system vibrator.
hide

Fields Summary
private static final String
TAG
private final IVibratorService
mService
private final Binder
mToken
Constructors Summary
public SystemVibrator()


      
        mService = IVibratorService.Stub.asInterface(
                ServiceManager.getService("vibrator"));
    
public SystemVibrator(android.content.Context context)

        super(context);
        mService = IVibratorService.Stub.asInterface(
                ServiceManager.getService("vibrator"));
    
Methods Summary
public voidcancel()

        if (mService == null) {
            return;
        }
        try {
            mService.cancelVibrate(mToken);
        } catch (RemoteException e) {
            Log.w(TAG, "Failed to cancel vibration.", e);
        }
    
public booleanhasVibrator()

        if (mService == null) {
            Log.w(TAG, "Failed to vibrate; no vibrator service.");
            return false;
        }
        try {
            return mService.hasVibrator();
        } catch (RemoteException e) {
        }
        return false;
    
private static intusageForAttributes(android.media.AudioAttributes attributes)

        return attributes != null ? attributes.getUsage() : AudioAttributes.USAGE_UNKNOWN;
    
public voidvibrate(int uid, java.lang.String opPkg, long milliseconds, android.media.AudioAttributes attributes)

hide

        if (mService == null) {
            Log.w(TAG, "Failed to vibrate; no vibrator service.");
            return;
        }
        try {
            mService.vibrate(uid, opPkg, milliseconds, usageForAttributes(attributes), mToken);
        } catch (RemoteException e) {
            Log.w(TAG, "Failed to vibrate.", e);
        }
    
public voidvibrate(int uid, java.lang.String opPkg, long[] pattern, int repeat, android.media.AudioAttributes attributes)

hide

        if (mService == null) {
            Log.w(TAG, "Failed to vibrate; no vibrator service.");
            return;
        }
        // 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(uid, opPkg, pattern, repeat, usageForAttributes(attributes),
                        mToken);
            } catch (RemoteException e) {
                Log.w(TAG, "Failed to vibrate.", e);
            }
        } else {
            throw new ArrayIndexOutOfBoundsException();
        }