Android Question [SOLVED] Can not work out how to set up an SMS client to receive SMSs

JackKirk

Well-Known Member
Licensed User
Longtime User
I am trying to set up an SMS client.

It has limited functionality - basically the app will reside on a dedicated phone - customers will read a sign saying something like "to get a free digital ticket SMS your first name to 04123123123" and react accordingly.

The app receives the SMS, extracts phone no and name and uploads an FTP job to an AWS EC2 instance that generates the ticket as an SMS back to the customer - all this backend stuff I have had working for a long time.

But I can't for the life of me get my app to receive SMSs

Attached is a minimal skeleton that illustrates my dilemma.

The Manifest is as follows:
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.

'Following required to enable this app to act as default SMS app, see:
'https://www.b4x.com/android/forum/threads/intent-filters-intercepting-sms-messages-in-the-background.20103/#content
'https://www.b4x.com/android/forum/threads/intercept-sms-messages-without-notification-android-4-4.37171/#post-227969
'https://android-developers.googleblog.com/2013/10/getting-your-sms-apps-ready-for-kitkat.html

'This allows app to directly receive incoming SMS messages
'android.permission.BROADCAST_SMS - allows an application to broadcast an SMS receipt notification
SetReceiverAttribute(service1, android:permission, "android.permission.BROADCAST_SMS")
AddReceiverText(service1, <intent-filter>
  <action android:name="android.provider.Telephony.SMS_DELIVER" />
  </intent-filter>
)
'This allows app to directly receive incoming MMS messages
'android.permission.BROADCAST_WAP_PUSH - allows an application to broadcast a WAP PUSH receipt notification
'    A WAP Push message is a binary encoded XML file that can direct a mobile phone to content
'    on web - used to send ringtones, wallpapers and games to mobile phones after the user has
'    sent a paid SMS to a provider
SetReceiverAttribute(service2, android:permission, "android.permission.BROADCAST_WAP_PUSH")
AddReceiverText(service2,  <intent-filter>
  <action android:name="android.provider.Telephony.WAP_PUSH_DELIVER" />
  <data android:mimeType="application/vnd.wap.mms-message" />
  </intent-filter>
)
'This allows user to respond to incoming phone calls with an immediate text message using app
'android.permission.SEND_RESPOND_VIA_MESSAGE - allows an application (Phone) to send a request to other applications
'    to handle respond-via-message action during incoming calls
SetServiceAttribute(service3, android:permission, "android.permission.SEND_RESPOND_VIA_MESSAGE")
SetServiceAttribute(service3, android:exported, "true")
AddServiceText(service3,  <intent-filter>
  <action android:name="android.intent.action.RESPOND_VIA_MESSAGE" />
  <category android:name="android.intent.category.DEFAULT" />
  <data android:scheme="sms" />
  <data android:scheme="smsto" />
  <data android:scheme="mms" />
  <data android:scheme="mmsto" />
  </intent-filter>
)
'This allows app to receive intents from other apps that want to deliver a message
AddActivityText(main,
 <intent-filter>
  <action android:name="android.intent.action.SEND" />
  <action android:name="android.intent.action.SENDTO" />
  <category android:name="android.intent.category.DEFAULT" />
  <category android:name="android.intent.category.BROWSABLE" />
  <data android:scheme="sms" />
  <data android:scheme="smsto" />
  <data android:scheme="mms" />
  <data android:scheme="mmsto" />
  </intent-filter>
)
Which is based on my reading of:

https://www.b4x.com/android/forum/t...sms-messages-in-the-background.20103/#content
https://www.b4x.com/android/forum/t...t-notification-android-4-4.37171/#post-227969
https://android-developers.googleblog.com/2013/10/getting-your-sms-apps-ready-for-kitkat.html

The Main activity is empty.

service2 and service3 are dummies.

service1 is as follows:
B4X:
'************************************************************************************
'************************************************************************************
'************************************************************************************
'
'This service provides a static broadcast receiver that will be started each time an
'SMS mssage arrives
'See:
'https://www.b4x.com/android/forum/threads/intent-filters-intercepting-sms-messages-in-the-background.20103/#content
'https://www.b4x.com/android/forum/threads/intercept-sms-messages-without-notification-android-4-4.37171/#post-227969
'https://android-developers.googleblog.com/2013/10/getting-your-sms-apps-ready-for-kitkat.html
'
'************************************************************************************
'************************************************************************************
'************************************************************************************

#Region  Service Attributes
'    #StartAtBoot: False
'    #ExcludeFromLibrary: True
#End Region

Sub Process_Globals

End Sub

Sub Service_Create

End Sub

Sub Service_Start (StartingIntent As Intent)
 
    Log("boo")

    Service.StopAutomaticForeground
 
End Sub

Sub Service_Destroy

End Sub

When I create a release version of the app on an Android phone I can change the phone's default messaging app to it - which I believe means I have done the manifest stuff properly.

But when I SMS the phone from another phone absolutely nothing happens (I would expect "boo" in the log).

Any guidance would be gratefully accepted...
 

Attachments

  • Freeticket.zip
    10.3 KB · Views: 240

JohnC

Expert
Licensed User
Longtime User
Instead of creating an app that needs to run on a dedicated phone that can breakdown, need a reboot every once in a while, etc...

You may want to simply setup a cloud based system that can send and receive SMS messages and interact with your own web server.

I have done this using Twilio.com's API. It only costs $1/mo for a phone number that you can then send and receive SMS messages from at only $0.02 per SMS message.

Basically, you can setup Twilio so that when it receives an SMS, it will then to do a "POST" to a webpage on your sever, providing the message and the sender's cellphone number. Your webpage can then run code to do whatever you want. Then the webpage could call another Twilio API to send an SMS message back to the customer.

Just a suggestion that might be a more reliable solution.
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
JohnC, thanks for the suggestion which I may pursue if I don't get a response to my first post.

As additional background this app would only be used during the first month or so of the projects life at each site and I was looking for a simple solution within my current skill set.

I have mastered the AWS SNS service for sending SMSs and I'm doing a lot of other related stuff on AWS so I'd like to avoid having to pick up another cloud platform if at all possible.
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
only $0.02 per SMS
Just dug a bit deeper and in Australia their send SMS charge is USD0.055 - compared to AWS at USD0.045

Might not seem much of a difference but I expect to be doing 10,000+ per month - it all adds up.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Check out SMS Retriever Library
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
Check out SMS Retriever Library
DonManfred thanks for the tip but it appears to me that if I use this library I am going to accumulate a whole mess of SMS's that I don't want - I was hoping to avoid this.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I am going to accumulate a whole mess of SMS's that I don't want
Yes? WHY?
Using the SMS Retriever Api your app starts a thread which waits up to 5 minutes to receive an SMS in a specific format.
This SMS can be retrieved without any special permission. You can send the SMS from whatever service. Even from AWS. The SMS must have a specific format.

And, by the way, it is Googles suggested Method for SMS Authentification.
 
Last edited:
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
Yes? WHY?
Using the SMS Retriever Api your app starts a thread which waits up to 5 minutes to receive an SMS in a specific format.
This SMS can be retrieved without any special permission.
If I read the info on the SMS Retriever Library properly the SMS ends up in the default messaging app where they will accumulate.

Also with the service approach, as I understand it, the app will automatically start when an SMS arrives - so no app management required just got to keep phone powered up.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
the SMS ends up in the default messaging app where they will accumulate
true- But your app DO GET the SMS-Info and also the code inside. So you can react in your app like you wish.
Note that the SMS comes into the default sms app inbox of the device running the sms retriever. Only the SMS for this device; not all SMSses.....
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
DonManfred, if I can get the original working I will have a simple solution to my requirement that does not accumulate SMSs and does not require any app management, do you have any clues to what I am doing wrong at post #1.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
wrong at post #1
you code looks like the code for a SMS APP. Is you app the default SMS app?
I know it was working fine in previous android versions. As i did not used it i´m not familar with the integration. Sorry, i can´t help here..
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
Upvote 0
Top