Here you can find the source of vibrate(Context context, int duration)
public static void vibrate(Context context, int duration)
//package com.java2s; import android.Manifest.permission; import android.content.Context; import android.content.pm.PackageManager; import android.os.Vibrator; public class Main { public static void vibrate(Context context, int duration) { if (hasVibrationPermission(context)) { ((Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE)) .vibrate(duration);/*from w w w.ja v a2 s . com*/ } } private static boolean hasVibrationPermission(Context context) { int result = context .checkCallingOrSelfPermission(permission.VIBRATE); return (result == PackageManager.PERMISSION_GRANTED); } }