How to keep playback active after the screen is turned off
Asked Answered
L

1

11

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.

Lazo answered 20/2, 2018 at 7:52 Comment(5)
try this #34628303Waers
try this #34628303Waers
From my experience it's better to use the Google way for a music app and extend their music service, look here: developer.android.com/guide/topics/media-apps/audio-app/…Anglian
@aliessa thanks, I've edited my question, playback runs in foreground service and app holds wakelockLazo
@Lazo Hi Sir, Did you found any solution to this problem? I also facing the exact same problem. Any help will be highly appreciated. Thanks.Spyglass
T
2

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.

Trust answered 25/2, 2018 at 19:48 Comment(1)
Thanks, my question is related to 3rd-party aggressive battery optimization and how to detect/alter it. There is problem only with some manufacturers and changing battery optimization settings always resolve issue. I've contacted Huawei support related to this issue. I will share more info once resolved.Lazo

© 2022 - 2024 — McMap. All rights reserved.