Whether the user has the screen on or off I want to notify the user by a vibration. If the screen is on, this works well:
Vibrator vibrator = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
long sleep = 100;
long vibrate = 500;
long[] vibratePattern = {0, vibrate, sleep, vibrate, sleep};
vibrator.vibrate(vibratePattern, -1);
Its called by a Thread that is implemented in a Service.
The Thread runs always even if the screen is off. I checked that because im implementing a timer. So that cant be the problem!