Hi,
I have built an mqtt service/process (using Itoo extension) that runs in the background which listens to an ESP32 and updates my app. When the app is closed it sends a notification (notificationstyle extension) and plays an alarm file (using a music player). This is used to alert for a critical situation.
Unfortunately when the mobile goes to doze mode after a few minutes the service stops. This could be a specific problem with my phone (Realme 8i) or the Itoo extension limitation. I have tried disabling every battery saving setting in the phone with no result.
I have also tried the extension "Keep alive" but didn't see any change. I hope I set it up correctly, see screenshot below.
Before I rule out completely this approach has anyone a suggestion ?
Looks like for this to work I will need to do FCM (Firebase cloud messaging) and "high priority messaging" which seems a bit complicated.
In that case I would prefer to use an API with my ESP and make a call using Twilio (paid service).
I've been running this for more than a week now (without battery optimizations turned off) on my Stock Android device, and it seems fine.
Just build and install the APK from the AIA attached above, and click the button, leave it running. It will constantly update the secs (updated value will be shown on screen).
Let me know how it goes. It would tell us if the device is really killing the background service.
I have just tried my test program for UrskeepAlive again on a Samsung cell phone with Android 12.
The app sends UDP packets at regular intervals so that I can check whether it is still active. It has now been running with the screen off for more than 40 minutes without any problems. The app runs in the background with an audio player running in the foreground.
The only modification is that I have activated developer mode on the phone. But that shouldn't make any difference.
I tried it works.BUT:
You display the result inside the app. If you send a notification using the notificationstyle ext it stops sending notifications after a few minutes. I send you the file to test it yourself (screenshot below). This tells me that only some functions go to sleep.
If you would be so kind as to try Kumaraswamy's changed code I sent. It should send a notification every 20 secs. If the phone goes to doze mode it stops sending (you can't hear the notification sound anymore). When you wake the phone it starts counting again (time is increased cause it has added the time before it goes to doze mode).
Hi, try to do this thing, before you close the app in the recents menu, do a long press on the application and select the "lock" option that would lock the application (will therefore keep it running)
ok that's a different App lock than the one I found in the settings which locks apps with password. The one I found cause the notifications not to work properly (shows only the number of notifications you have but not their full description)
Since you are using the project for personal use, we could try with IGNORE_BATTERY_OPTIMIZATION permission, I guess that one of @Taifun's extension offer this feature?
I tried and it doesn't work continuously. You can hear the sound sporadically in random occurrences. From a few secs to minutes. That's strange. I think in doze mode it should wake up in fixed periods.
Your app works only if it's open. The app with the Itoo extension woke up at 10 min intervals, which seems more logical.
This is all android background stuff which needs an expert to clarify
I've been working with background stuff for years now, yet im still not an expert, there is a lot of unnecessary diversity in the Android ecosystem.
Try this thing that allows you to ignore battery optimizations. By Taifun:
It is important to note that when you use Itoo, it automatically applies indefinite wakelock by default, so using UrsAI2WakeLock extension wouldnt make a difference.
I have almost 20 test devices, most of them with Android ≥ 6 (i.e. after the introduction of Doze mode). The APK works on all devices. So it must be a device-specific "abnormality".