do Short Vibrate - Android Hardware

Android examples for Hardware:Vibrator

Description

do Short Vibrate

Demo Code


//package com.java2s;

import android.os.Vibrator;

public class Main {
    private static Vibrator _vibrator = null;

    public static void doShortVibrate(int times, int gap) {
        if (_vibrator != null) {
            long[] vibrateScript = new long[times * 2];

            for (int i = 0; i < vibrateScript.length; i++) {
                if (i == 0) {
                    //Rest time gap
                    vibrateScript[i] = 10;
                    continue;
                }//www.j  a v  a  2 s .c  o  m
                if (i % 2 == 0) {
                    //Do vibrate time
                    vibrateScript[i] = 100;
                } else {
                    //Rest time gap
                    vibrateScript[i] = 10;
                }
            }

            _vibrator.vibrate(vibrateScript, -1);
        }
    }
}

Related Tutorials