Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep playback active after the screen is turned off

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.

like image 301
majov Avatar asked Feb 20 '18 07:02

majov


People also ask

How do I make my screen stay on all the time?

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.

How to turn off your laptop screen?

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 I Keep Music on when my screen is off?

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?

How do I turn off a movie after it is played?

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).


1 Answers

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.

like image 173
Silverstorm Avatar answered Sep 19 '22 07:09

Silverstorm