问题
Seriously, What is the solution to do a simple task like sending notifications when app is not running? (Using devices with custom OS like Xiaomi)
When alarm is set, it works for short period of times like a few minutes, but not for long periods of time like hours. (although it works perfectly fine on some devices and also when the app is running)
I have read hundreds of threads and no one has a concrete solution for this. None of the recommended methods work, I tried the following:
- Alarm manager + Broadcast Receiver + BackgroundService (Works on some devices, not all)
- Alarm manager + Broadcast Recevier + foregroundService (worked a few time but then just stopped working!) I tried intentservice, jobintent service and none worked.
- WorkManager (the work is delayed indefinitely, some times 15 minutes some times an hour, some times 10 hours)
- Added Wakelock (didin't change anything)
- Alarm manager + IntentService (doesn't work)
- Setting a process name to the service(doesn't change anything)
- Some thread and also Google guys say that there is no solution at the moment. However I have seen apps that managed to make it work!
I read about dontkillmyapp and I am aware of the issue. But I have one app that somehow managed to send notifications at very exact times. It is not a famous app like Whatsapp. There must be a solution.
来源:https://stackoverflow.com/questions/63501496/substitute-for-alarm-manager-android