I have a BroadcastReceiver in my android application. I want to vibrate when something special happen in my Receiver.
I know how to control vibrate, but there are 2 problems:
1- When power button pressed and screen gets off device stops vibrating. 2- After turning on Screen again if my vibration repeat parameter set to more than 1 it never vibrate again.
here is my vibration method:
public void startVibrate(Context context, int repeat) { vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); int dot = 200; // Length of a Morse Code "dot" in milliseconds int dash = 500; // Length of a Morse Code "dash" in milliseconds int short_gap = 200; // Length of Gap Between dots/dashes int medium_gap = 500; // Length of Gap Between Letters int long_gap = 1000; // Length of Gap Between Words long[] pattern = { 0, // Start immediately dot, short_gap, dot, short_gap, dot, medium_gap, // S dash, short_gap, dash, short_gap, dash, medium_gap, // O dot, short_gap, dot, short_gap, dot, long_gap // S }; vibrator.vibrate(pattern, repeat); //vibrator.vibrate(10000); } here is vibration method call:
controller.startVibrate(context, 0);