0

Since android 8 the OS has placed may restrictions on how and when can the apps use Broadcast Receivers and Services.

TL;DR: Starting Android 8 the OS will stop your Services and Broadcast Receivers except in some situations mentioned in above documents.

What is then a proper way to detect incoming sms? We can use WorkManager to manually query the SMS to check for new entries every 15 minutes. But what would be a way to get it instantly?

Also the official docs list the SMS_RECEIVE intent in the list of broadcasts that are exceptions to the above rules, but many have found that the receivers and services still get terminated and I have confirmed that by testing it myself.

There are some spend tracking apps out there that still do track the incoming sms regardless of the situation.

Would appreciate any inputs on the situation.

Thanks.

Shounak Mulay
  • 39
  • 1
  • 7
  • 1
    The proper way to get incoming SMS as they arrive has always been a statically-registered `BroadcastReceiver`. Standard Android is not just gonna disable one of those randomly, so if that is indeed what's happening in a particular case, then that's likely due to a manufacturer's modifications, which would require a manufacturer-specific solution, and those are rarely able to be done programmatically, as far as I've seen. If anything beyond the `BroadcastReceiver` is failing – e.g., a `Service` not starting, or being stopped prematurely, etc. – then that's not really an issue with SMS receipt. – Mike M. Jun 25 '20 at 12:03
  • Thanks for the quick answer @MikeM. That makes sense. I am using a Xiaomi device to test. That could be why I am seeing these results. Well good to know that `BroadcastReceiver` is the correct way to go. – Shounak Mulay Jun 25 '20 at 12:30
  • 1
    Yeah, that manufacturer's devices often have additional restrictions that prevent most third-party apps from doing certain things – e.g., receiving SMS, running in the background, etc. – without the user having explicitly allowed it. You can try to locate settings for those, and make sure your app is allowed. I've never used such a device, so I can't tell you where to go specifically, but check these posts: https://stackoverflow.com/q/30748107, https://stackoverflow.com/q/37927565, https://stackoverflow.com/a/35770734, https://stackoverflow.com/q/48166206, https://stackoverflow.com/q/55258440 – Mike M. Jun 25 '20 at 15:28

0 Answers0