- All Known Implementing Classes:
AndroidVibrationService
,DummyVibrationService
,IOSVibrationService
public interface VibrationService
The vibration service enables access to the vibration functionality present
on most devices. It allows alerting the user when notification through sound
is inappropriate or unavailable.
Example
VibrationService.create().ifPresent(service -> {
service.vibrate();
});
Android Configuration
The permission android.permission.VIBRATE
needs to be added.
<manifest ...>
<uses-permission android:name="android.permission.VIBRATE"/>
...
</manifest>
iOS Configuration: none
- Since:
- 3.0.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic Optional<VibrationService>
create()
Returns an instance ofVibrationService
.void
vibrate()
Vibrates the device with the default pattern and durationvoid
vibrate
(long... pattern) Vibrates the device with the given pattern, which represents the number of milliseconds to turn the vibration on for, followed by how long it should be off for.
-
Method Details
-
create
Returns an instance ofVibrationService
.- Returns:
- An instance of
VibrationService
.
-
vibrate
void vibrate()Vibrates the device with the default pattern and duration -
vibrate
void vibrate(long... pattern) Vibrates the device with the given pattern, which represents the number of milliseconds to turn the vibration on for, followed by how long it should be off for.In the simple case of a single vibration, a call of
vibrate(2000)
will result in the vibration running for 2 seconds before stopping.If a pattern is desired, multiple durations can be provided, where each odd duration represents a vibration duration, and each even duration represents an amount of time to wait. For example, a call of
vibrate(1000, 1000, 2000, 2000, 3000)
will result in the following pattern:- Vibrate for 1 second
- Wait for 1 second
- Vibrate for 2 seconds
- Wait for 2 seconds
- Vibrate for 3 seconds
vibrate()
- Parameters:
pattern
- The pattern of durations to play the vibration for (with wait periods in between).
-