7

My app plays streamed audio in the background using Exoplayer but the system is shutting it down if the user doesn't whitelist us manually in the battery optimization settings.

There are other apps also running streamed audio in the background successfully without interruptions and without whitelisting in the battery optimization.

This is the code to take the user to settings app, with some instructions on how to do it. But each system has its own way / path to disable the battery optimizations, making our instructions not always accurate:

           Intent myIntent = new Intent();  
           myIntent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
                            startActivity(myIntent); 

Is There a way to whitelist us without prompting the user and be accepted in the review process? Or is there another way to avoid the system shutting down our streaming?

Thank you!

neowinston
  • 7,584
  • 10
  • 52
  • 83
  • 5
    There is no way to be whitelisted automatically or programatically except by the OEM who installed the system. That's the purpose of the whitelist. – Gabe Sechan Dec 05 '18 at 21:54
  • @GabeSechan I think the whitelist Winston's referring to is the "battery optimization" settings screen (described [here](https://developer.zebra.com/community/home/blog/2018/10/26/keeping-your-application-running-when-the-device-wants-to-sleep)) where you can "exempt" individual apps. – greeble31 Dec 05 '18 at 22:09
  • 3
    @greeble31 yes. And you can't add yourself to it programmatically, on purpose. Because then every app would do it – Gabe Sechan Dec 05 '18 at 22:10
  • @Winston you didn't mention a foreground service... are you sure that isn't the problem? – greeble31 Dec 05 '18 at 22:12
  • @greeble31 I'm using a foreground service. It runs fine with older versions of Android that doesn't have the battery optimization feature. Thanks for pointing that out. – neowinston Dec 06 '18 at 15:48
  • @Winston I think that the real question you should be asking is, "why doesn't exoplayer work consistently on Android 8.0+, without having to guide the user through the manual whitelisting process?" It seems to me that the exoplayer community would be howling if this problem didn't already have a solution. – greeble31 Dec 06 '18 at 20:57
  • @greeble31 You're right. Searching about this audio issue on Exoplayer docs I found that it's necessary to use Wakelock and Wifilock. I'm testing it now and it seems to solve the problem. – neowinston Dec 06 '18 at 21:13
  • 1
    @greeble31 as you pointed out, my problem was with foreground service. – neowinston Aug 27 '19 at 16:16
  • @Winston could you specify what you mean by the problem with foreground service. I understand you were already using one - did you misconfigure something. How did you resolve the issue on Android 8.0 and higher? Thanks. – gswierczynski Sep 17 '19 at 00:42
  • @gswierczynski what I meant was that at that time I didn't have a clear understanding of the difference between an audio background task/service and a foreground service. I did have my audio working on a background task/service, which was enough for systems without the doze feature, but not enough for later systems with the doze feature. I hope this helps you somehow also. – neowinston Sep 18 '19 at 15:00
  • @Winston Oh, I see. In theory foreground service should not be interrupted by any battery optimizations, but I read reports that some of the manufactures do not respect foreground service and kill the process anyway. Just exploring the matter. Thank you for taking time to clarify what you meant. – gswierczynski Sep 19 '19 at 21:38
  • @gswierczynski No problem, glad to communicate! – neowinston Sep 24 '19 at 14:06
  • Were you able to disable battery optimisation work across all manufactures with the code snippet you shared above? I am running a foreground service, but as @gswierczynski mentioned I found that not all manufactures (Especially Samsung and Xiaomi) don't respect the same. And they also seem to have different settings for disabling battery optimisation. Any clue on how to make it work across all manufactures? – leenasn Feb 25 '20 at 07:27
  • 1
    I never found an universal solution for the battery optimization problem. But in my case just running the foreground service solved the problem. – neowinston Feb 25 '20 at 16:53

0 Answers0