Java tutorial
//package com.java2s; import android.app.Service; import android.content.Context; import android.os.Vibrator; public class Main { private static Long time = 0L; public static void Vibrate(Context context) { if (System.currentTimeMillis() - time > 1000) { long[] pattern = { 100, 300, 100, 300 }; Vibrate(context, pattern, false); time = System.currentTimeMillis(); } } public static void Vibrate(Context context, long milliseconds) { try { Vibrator vib = (Vibrator) context.getSystemService(Service.VIBRATOR_SERVICE); vib.vibrate(milliseconds); } catch (Exception e) { e.printStackTrace(); } } public static void Vibrate(Context context, long[] pattern, boolean isRepeat) { try { Vibrator vib = (Vibrator) context.getSystemService(Service.VIBRATOR_SERVICE); vib.vibrate(pattern, isRepeat ? 1 : -1); } catch (Exception e) { e.printStackTrace(); } } }