I have created an app that gives the user vibration alerts when tilting the phone in a certain direction. It works fine when running the app, however, when closing the window to run the app in background, the vibration stops working. How can I enable it in background?
vibrator.vibrate(VibrationEffect.createWaveform(new long[] {0, 1000}, -1));
I also have
<uses-permission android:name="android.permission.VIBRATE"/>
In addition to @MarcM answer, add "startMyOwnForeground" and it should work with Android 9+
In your fragment:
VibrationService.java