1

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); 
4
  • 1
    I just have to ask... Why? This seems like a bad idea from the users perspective. Not to mention a battery killer. Commented Nov 7, 2014 at 1:25
  • Are you sure that you want your users to make VooDoo dolls with your name and put nails in them because you drain their device's battery? Commented Nov 7, 2014 at 8:20
  • dudes please answer and don't judge my app. Commented Nov 7, 2014 at 11:36
  • try to change the repeat value to zero. Commented Jun 20, 2015 at 19:42

1 Answer 1

2

I know i am answering very late but it might help anyone so if you don't want to repeat pattern you pass -1 to repeat pattern.

Vibrator.vibrate(pattern, -1);

https://developer.android.com/reference/android/os/Vibrator.html

Sign up to request clarification or add additional context in comments.

1 Comment

That method has been deprecated as of API 26 (Oreo)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.