Vibrate by pattern - Android Hardware

Android examples for Hardware:Vibrator

Description

Vibrate by pattern

Demo Code


//package com.java2s;
import android.app.Activity;
import android.app.Service;
import android.os.Vibrator;

public class Main {
    public static void Vibrate(final Activity activity, long milliseconds) {
        Vibrator vib = (Vibrator) activity
                .getSystemService(Service.VIBRATOR_SERVICE);
        vib.vibrate(milliseconds);//from   w  ww. j a  va 2s.  co m
    }

    public static void Vibrate(final Activity activity, long[] pattern,
            boolean isRepeat) {
        Vibrator vib = (Vibrator) activity
                .getSystemService(Service.VIBRATOR_SERVICE);
        vib.vibrate(pattern, isRepeat ? 1 : -1);
    }
}

Related Tutorials