Android Question Complete SMS intercepting example after KitKat

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
I've found many different posts across a large time span using both direct intent filtering and the SMSinterceptor object from the Phone library with different bits of code/manifest snippets scattered throughout the threads but I have not found one consolidated working example of intercepting/sending a SMS message and preventing it from reaching the default handler that anyone has posted / uploaded.

So, to sum up:

1. The SMSInterceptor object is now more of an "SMSEavesdropper" and the Boolean return value from the event handler is ignored, correct?

2. From Erel's reply in the https://www.b4x.com/android/forum/t...t-notification-android-4-4.37171/#post-227969 post it seems you need to add manifest text for three services, then create three services following the code template from Erel's tutorial at https://www.b4x.com/android/forum/t...cepting-sms-messages-in-the-background.20103/ changing the intent you're looking for in each service to match the manifest entries. My question, why have three different services? Could you not just have one service and parse the intent in the Service_Start, or would that create issues with simultaneous sends/receives?

3. Does anyone have a short, working, example project on Android 4.4+ that they would be willing to share which sends/intercepts SMS messages and prevents them from reaching the default message handling app?

TIA

Edit -- Also, if #1 is correct you should probably update the Phone Library documentation at (https://www.b4x.com/android/help/phone.html#smsinterceptor)
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Yes.
2.
My question, why have three different services?
It will probably work with a single service as well.

3.
Does anyone have a short, working, example project on Android 4.4+ that they would be willing to share which sends/intercepts SMS messages and prevents them from reaching the default message handling app?
The only way to intercept (and consume) messages is if your app is set to be the default SMS app.
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
Ok, if the only way is to make your app the default, what is the point of the example in #2 above? I seem to be getting messages just fine using the SMSInterceptor in a run-at-boot service. Do I need to go to the all the trouble of the example in #2 and add the manifest text for a specific reason or will the SMSInterceptor be enough as long as I don't want to make my app a "default" messaging app?

As a side note, when I got my new car I installed the "Nissan Connect App" and I do not recall making it the "default" messaging app yet it prevents my phone from alerting when I get texts when it is connected via Bluetooth to my car. How is that?
 
Last edited:
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Additionally: As I know when registering to WhatsApp a SMS is sent to the device to check if the phone number is valid. This SMS is deleted after the check.

How is WhatsApp doing this? Setting itsself to the standard sms app isn't possible.

Edit: Or they SEND an sms. But same question: How do they delete it?
 
Last edited:
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User

I don't know enough about the Android nuts-and-bolts to be able to comment on this possible solution. According to what I've found on the Google developer site (https://developer.android.com/reference/android/provider/Telephony.html) what we want to do is just not possible post KitKat.

Hopefully someone who knows more than I may investigate :)
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Maybe there is a private API

I thought Android keeps an eye on permissions so even an own lib won't do I think. WhatsApp uses a SMS to identify the device (to get & check the phone number via simple SMS with a generated token).

Either they receive a SMS and delete it after or (more likely) they send a SMS and delete it after. However: They delete it (I did not check if the SMS was on my bill. They did not tell that there may be costs due to sending it).

It seems that "some" apps can do more than others by magic :)
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
There is a legend if you get persission to write SMS and you wait at least 10 second after SMS receipt you can delete it in every android version. I'm trying since I have the same need! WhatsApp sends the SMS from their servers so the bill doesn't show it.

Mauro
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Ok, if the only way is to make your app the default, what is the point of the example in #2 above? I seem to be getting messages just fine using the SMSInterceptor in a run-at-boot service. Do I need to go to the all the trouble of the example in #2 and add the manifest text for a specific reason or will the SMSInterceptor be enough as long as I don't want to make my app a "default" messaging app?
All the trouble? It will take you 4 minutes to implement it. The advantage is huge. Your app will not need to run all the time in the background in order to intercept messages.

StartAtBoot will not really help you. Android will kill the process and you will not receive messages (unless you call Service.StartForeground which has its issues as well).
 
Upvote 0

janderkan

Well-Known Member
Licensed User
Longtime User
Every operator has a SMSC (ShortMessageServiceCenter), this works as a post office.
Every message goes through the SMSC.
You can buy an IP connection to the SMSC, and have a 3 or 4 digit 'phonenumber'
Using this connection you have total control of messages and can send hundreds or more pr. second.
You can send a message with any number or a text as originator.
You can monitor the state of the SMS, received, read, deleted ..
And you can delete it.
Some of this functionality is available if you use a GSM modem in PDU mode.
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
All the trouble? It will take you 4 minutes to implement it
Yes, but it took me 4 seconds to implement the SMSInterceptor, if it worked as advertised ;) . By "all the trouble" I was implying all the new intent handling and code required to make a complete SMS app.

If I want my app to send/receive messages to the customers of my app clients, as I understand it now, I have two options:
  1. Use the SMSInterceptor, and just let all the messages my app needs/sends pile up in the SMS history, displaying spurious message received notifications, etc., or
  2. Make my app the default message app which entails doing everything a "normal" messaging app would, handling the history, interfacing with contacts, "send with" intents, etc.
I understand this is an OS limitation, nothing to do with B4A, and in terms of complexity to me it seems like you get a choice of swatting at the mosquito with your hand or using a howitzer to kill it. Some type of middle-ground "fly-swatter" solution would seem to be in order.
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
You can buy an IP connection to the SMSC
There are several services available that you can subscribe to that provide a limited number of messages/month for a fee or charge a few cents per message sent. Since my customers generally have "unlimited" text and data, I was trying to leverage the services they are already paying for rather than have another fee they need to budget ;)
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Yes, but it took me 4 seconds to implement the SMSInterceptor, if it worked as advertised ;) . By "all the trouble" I was implying all the new intent handling and code required to make a complete SMS app.

If I want my app to send/receive messages to the customers of my app clients, as I understand it now, I have two options:
  1. Use the SMSInterceptor, and just let all the messages my app needs/sends pile up in the SMS history, displaying spurious message received notifications, etc., or
  2. Make my app the default message app which entails doing everything a "normal" messaging app would, handling the history, interfacing with contacts, "send with" intents, etc.
I understand this is an OS limitation, nothing to do with B4A, and in terms of complexity to me it seems like you get a choice of swatting at the mosquito with your hand or using a howitzer to kill it. Some type of middle-ground "fly-swatter" solution would seem to be in order.

So you can set your app as the standard sms app by code without user action? (= good). If the answer is "NO" than back again: How does WhatsApp do it (by a special framework? which is mentioned by tigrot)
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
So you can set your app as the standard sms app by code without user action?
No, you cannot do it via code, that part I'm clear on.

You can have your app detect if it is the default app and if not then exit (or start an intent to settings to pick the default app and then exit).
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
After lot of tries, I'm still level zero. I need a way to get confirmation for phone number the user enters in a field. I have a small server (in a five cents 2.3.6 Android) It gets the SMS, sends the result(complete with the phone number) to the user via Firebase Cloud Messaging. And the work is done without receiving anything on the customer's phone. I don't expect milions of customers at the same time(I wish...).
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Yes, but it took me 4 seconds to implement the SMSInterceptor, if it worked as advertised
You are confusing different things. The difference between SmsInterceptor and the solution based on an intent filter (not default SMS app) is that SmsInterceptor will only work while the process is running while the intent based solution will always work.
 
Upvote 0
Top