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.