androidsmsandroid-broadcastreceiver

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


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


Solution

  • 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 a statically registered Receiver for the implicit SMS_RECEIVED broadcast won't work until your app has been explicitly started again; e.g., by the user launching your app from an explicit launcher shortcut.

    The default SMS app, on the other hand, will be delivered the SMS_DELIVER broadcast, and that is explicit. Even if the default has been forcibly stopped, that broadcast will act like any other explicit starting Intent to bring it out of the stopped state.

    If timeliness isn't a major concern, you could just query the SMS Provider as needed – e.g., at each startup – and determine if you've missed any new messages since last checked.