Can non-default SMS app ALWAYS receive broadcast when SMS received, even when force closed?

北战南征 提交于 2019-12-10 20:13:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!