Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.os.Vibrator; public class Main { private static final long[] SHAKE_PATTERN = { 300L, 200L, 300L, 200L }; /** * msg shake * * @param context * @param isShake */ public static void shake(Context context, boolean isShake) { Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); if (vibrator == null) { return; } if (isShake) { vibrator.vibrate(SHAKE_PATTERN, -1); return; } vibrator.cancel(); } }