2

I am using nearby connections API from a foreground service to find other devices and share data with them. It works even if the app is not in the foreground. That happens pretty fast like in 5-15 seconds. But when device enters doze mode like when screen goes off than it stops working. I found a way to ignore battery optimizations and can so continue to work from foreground service even when screen is off BUT the time needed to find and share data between devices is increased to 30-45 seconds. Is there a way to "speed up" this process while in doze mode? Or maybe are there some other tools that I might use to share data with my app on android devices near me even when device has screen off?

Youssif Saeed
  • 11,789
  • 4
  • 44
  • 72
Gamer Pro
  • 23
  • 3

1 Answers1

2

Unfortunately there's no way to completely eliminate the possibility of your app being terminated or slowing down. This is because in Android P and later, the OS has an adaptive battery feature that can limit the time a service remains in the foreground. Your best bet is to request that users turn their battery optimisation off as you mentioned in your question.

Below are a few links that go over the subject of foreground services and battery optimisations:-

Youssif Saeed
  • 11,789
  • 4
  • 44
  • 72