问题
So I have followed this guideline to show a simple toast when SMS is received. While it works ok when app is running, when I go to settings and force-close the app, it stops working.
I checked many answers here on StackOverflow for simmilar questions, but none actually answers whether (and how) it is possible to make a piece of code execute EVERY time SMS is received, without the app being set as the default SMS app on device (Android 4.4+). Is it?
Consider that even service can be stopped, and when that happens, service is not a solution anymore.
I am interested in API level 19+
Thanks
回答1:
Unfortunately, no, this isn't really possible without your app being the default SMS app. When the user forcibly closes your app, it is put back into the stopped state, and its statically registered Receivers won't work until the user runs your app again. The default SMS app is special in this regard, as the system will still start it to process the SMS_DELIVER
broadcast, even if you forcibly stop it.
If timeliness isn't a major concern, you could just query the SMS Provider each time your app runs, and determine if it's missed any new messages since last it ran.
来源:https://stackoverflow.com/questions/34012158/can-non-default-sms-app-always-receive-broadcast-when-sms-received-even-when-fo