I have an app with audio playback, but on some devices (mainly Huawei, Samsung, Sony) playback is stopped when the screen goes off. Note: playback does not stop for some other apps like Spotify, Play Music
I found this answer (for Huawei devices) which suggest to ask user to enable "run in background" permission in battery optimization settings (Battery Manager > Protected Apps) but I would like to avoid asking users to enable it.
Is there some API to enable it programmatically for Huawei, Samsung, Sony or other manufacturers?
Is it possible to detect if app do not have such permission?
EDIT: playback runs in foreground service and app holds wakelock
EDIT 2: I've contacted Huawei support related to this issue. I will share more info once resolved.
To ensure your display is always on, select Never from the drop-down menu and click Save changes. Now, your PC display should never turn off until you close the lid. You can also keep the display on without configuring any Windows 10 settings by using third-party software.
Hence, the first and best method to turn off your laptop screen is to change the power button action. Here’s how you can do that: Click on the Windows logo on the left corner of your screen to find and open Control Panel. Next, navigate to Hardware and Sound. Under Power Options, tap on Change what the power buttons do.
How do you keep music playing on Android? Navigate to Settings, and then search for and select Special access. Tap Allowed to use data while Data saver is on again, and then tap the switch next to the music app you want to keep running. Why Spotify stops playing when screen is off?
To set an action, right-click on the playing movie or the player screen, and find the context menu entry for “After Playback”. Divided in two sections – Once and Every time – you can choose to Exit, Stand By, Hibernate, Shutdown, Log Off, Lock, or Do Nothing (default).
Use a service with foreground priority the newer Android OS versions have a doze function to save battery.
If you already use the service in foreground probably there is something wrong with the way you use the service in your code (give more details).
Here a tutorial about Playing music in the background that could help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With