0

I've been developing an Android app that allows the operator to control equipment through API calls, which are sent and received via text messages.

Since we want people to still be able to use their phones as phones, we still want users to be able to send and receive text message with the built-in SMS app.

However, the issue with my app is that it is not the default SMS app, which means that these control messages:

  • Look like total garbage, so I would want to be able to delete these messages from a user's inbox (or have them never reach the inbox).
  • They also show a notification, since they're an SMS message and are handled by the system SMS app as such.

If I block a number, using the built-in SMS app, my app won't receive it either - so the logic, therefore, is to make my app the default SMS app so that it can intercept all messages before deciding how they should be handled. The problem now is that no other messages will reach the built-in SMS app.

One way around this is to forward messages to this built-in SMS app's inbox, but the built-in SMS app would no longer be able to send messages.

The inevitable answer that I expect is the only technically viable option is that I will have to implement a full SMS client in its entirety; however, this seems a really poor approach to me and massively pollutes the scope of development.

Is there really no way for me to create a default SMS app that can then "forward" an incoming SMS to either the built-in SMS app or my own app (for controlling the aforementioned machinery)?

Trevelyan
  • 87
  • 10
  • Considering that the SMS system is very insecure and has per-message fees for many people, I suggest that you do something else for controlling this equipment. – CommonsWare May 29 '19 at 11:12
  • This was not a question about the security or cost of data transportation, it's about how technically possible it would be. The application is somewhat irrelevant, since there may be others who have a similar requirement. – Trevelyan May 29 '19 at 15:31
  • To elaborate further; others may have some similar requirement, which could be derived from situational quirks, such as 2g-only coverage, cellular hardware limitations, corporate oddities and legacy constraints. For that reason, I think this is a valid question (even if the answer highlights the technical compromises that need to be made) – Trevelyan May 29 '19 at 15:38
  • 1
    "This was not a question about the security or cost of data transportation, it's about how technically possible it would be" -- my comment was also for the benefit of others who encounter your question. IMHO, there are few places where SMS as a control channel is a sensible choice, and fewer still where that device is also for use by an actual user. I want people to think through the ramifications of their choice. – CommonsWare May 29 '19 at 15:49

2 Answers2

0

Android is not set up to work the way that you seek, except prior to Android 4.4, due to rampant abuse. Your options are:

  • Limit users of your app to Android 4.3 or older devices, in which case the SMS_RECEIVED broadcast is an ordered broadcast that you can cancel. This approach will be impractical due to the small number of active older devices, plus the challenges of limiting distribution to those devices.

  • Use createAppSpecificSmsToken() on SmsManager. This gives you a token that, if it is included in an SMS message, causes that message to be re-routed to your app by means of the supplied PendingIntent. However, these are one-time-use tokens, so you would need to be able to tell your server the next token to use, including the first token to use after app installation. It further implies that you have a server capable of tracking and using those tokens, and that may or may not be part of your overall system architecture. Also, createAppSpecificSmsToken() is only available on API Level 26+ (Android 8.0+).

  • Find a third-party SMS client that offers a plugin interface, and implement a plugin that meets your requirements. Then, require users of this equipment to switch to that SMS client.

  • Contribute a plugin interface to an existing open source SMS client project, then proceed as in the preceding bullet.

  • Write an SMS client, either from scratch or based off of an existing open source project, and have users of this equipment switch to that SMS client.

  • Require a rooted device and figure out some magic (e.g., Xposed module) that will allow you to handle SMS messages more to your liking. I presume that this is possible, as there are lots of creative uses of root, though I do not know if this specific thing is possible.

  • Create a custom ROM that handles SMS messages more to your liking, then require users of this equipment to install that custom ROM.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
0

Use port-addressed data (binary) SMS. These are routed directly to your app on the way in, bypassing the "default SMS app". Outgoing binary SMS are also not stored in the "default SMS app"s SENT or OUTBOX, so your users won't see them.

See http://codetheory.in/android-sms/ for details about how to do this, or search Stackoverflow or other sites for howtos or tutorials for sending and receiving port-addressed data (binary) SMS.

David Wasser
  • 93,459
  • 16
  • 209
  • 274
  • Hi, looks like the codetheory.in site is down/not working. Do you know of any other source for their article on binary SMS? – AJW Jul 16 '20 at 03:11
  • 1
    @AJW have a look at this question and the linked examples https://stackoverflow.com/questions/8972905/working-example-of-senddatamessage-for-android If you have a specific problem you can open a new question on Stackoverflow – David Wasser Jul 16 '20 at 09:56