Closed rbluethl closed 2 years ago
Hey @rbluethl Thanks for checking out the package. To answer your questions
Yes listening in the background will work even if you don't open the app. The reason this works is we are registering a static broadcast receiver in the app's manifest file. That means the android system can initialize that broadcast receiver independent of the app.
In most cases the device manufacturers and custom android OS environments block most of the app from performing operations in the background. That means your app won't receive any broadcasts and if it tries to start services in the background those will be killed as well. Don't kill my app is a good place to look at what particular device manufacturers are doing in terms of blocking background operations. If you are facing this problem there isn't much we can do as app developers other than asking the user to turn off battery optimization.
The notification that you see from other apps comes from a Foreground Service. Telephony uses a Broadcast Receiver and not a Service. Incoming SMS on android are generally detected using Broadcast Receivers and not Services.
Listening to SMS or doing any background work, in general, comes down to how time-sensitive is the task.
All of these approaches are still vulnerable to the above mentions restrictions from the device manufacturers. Unfortunately, there is no way around it as of yet. If optimizations are turned off for your app or the if the device does not block background tasks aggressively (eg. Google, Motorola devices) these methods are pretty reliable.
Hope this answers all your questions.
Hey @shounakmulay! Thank you very much for your comprehensive answer - you're doing a great job at carefully responding to all kinds of issues/questions.
You definitely answered all my questions, thank you again!
Following the docs should be enough. Because we register the receiver statically the app doesn't need to be open after every restart.
Issue marked stale due to no activity.
Listening to incoming SMS in background is not working !
Hey! I've been intensively digging through all (open & closed) issues regarding listening in background and listening when the app is closed, however I'm still not quite sure if I'm doing everything right.
In #71 it is mentioned, that it should be possible to listen to incoming messages even when the app is closed. Is that really the case? What if I start my phone and do not explicitly open the app, how should it be possible that the app still receives incoming messages?
In #90 you say that "The package does support running when the app is closed. The reason it may not work as expected in most cases is that the device blocks the background execution of the app.". Does that mean it should basically work without any further ado?
From other apps I have seen alerts in the notification center that an app is running in the background (see attached screenshot). Is that even necessary/does Telephony do something differently?
It's not entirely clear to me how reliably listening in the background should be approached. Maybe you could elaborate a bit @shounakmulay ? Do you think that it's always necessary to tweak the battery settings depending on the device/manufacturer? Thank you for being so kind and developing this helpful package!