How do I simulate SMS Received?

Hi @SteveJG thanks for support. That's what I'm doing for the moment, but every test I have to build the APK download it on the mobile and test it. I thought the thing had been planned.
This answers the main question!
Concerning the reception and processing of an SMS with this example it does not work, there is a trick?

No trick. You have to set ReceivingEnabled property as indicated in the Texting documentation.

If the ReceivingEnabled property is set to 1 messages will not be received. If ReceivingEnabled is set to 2 messages will be received only when the application is running. Finally if ReceivingEnabled is set to 3, messages will be received when the application is running and when the application is not running they will be queued and a notification displayed to the user.

AND you must use Companion 2.60 so you can use and expose the SendMessageDirect() to send a text message automatically Using this block will add dangerous permissions that will require additional approval if your app is submitted to the Google Play Store.

Don't use the Send Message Direct Block in the Screen1.Initial use an EventHandler in the main app.

Not sure to understand what it means?
By default I put for both, SMS1 & Texting1 to "Foreground" that's the same as "2" I think ?
Prop_SMS
Prop_Text
Or you need both, on Properties & Block ? In that case how to place "EventHandler" if is not in Screen1.Initial ?

You are using TWO Texting components? I don't think that will work. :cry: Use only one.

1 is Off, 2 is Foreground, 3 is Always smsReceiving

  • use a Button instead of Screen1.Initialize or a Clock ?

  • a suggestion. Until you get the Receiving working, don't try to use the Arduino. Keep it simple and establish whether sms messages are being received using ordinary text messages.

Yes, I'm trying first with SMS1, it does not work, so I add a textting1 that does not work too!
I am not sure to understand what are the differences between the two ...
I started both out of 2 (foreground) and I use Companion 2.60.
When I manually send an SMS "State" to the Arduino, I return, "On" or "Off", so when the API starts, I send an SMS to retrieve the state of the Arduino "On" or "Off" But the API does not detect the SMS.

Have you done the NoTextingWhileDriving tutorial? If not, do that first before attempting to work with the Arduino. Read No text while driving compiling not working - #10 by Nicholas_Cossentino the discussion talks about NTWD changes to the original tutorial necessitated by recent Google security requirements.

Can you confirm you have the NTWD app working by sending a Text message to yourself?
because at the moment

and you cannot really test using the Arduino until you establish whether the Android code is working. Your problem might be with the Arduino sending the message.

No, sorry my code Arduino works well! I use it for 2 years now and whenever I spend textual SMS, I get an answer by SMS back from Arduino. The worry is not the!
My problem is to read an SMS with AppInventor 2 and not to be able to find a good example to do it!
I will try with NoTextingWhileDriving and see what's going on!

The Screen1.initialize work fine. Each time I start the API on smartphone that send an SMS to my Arduino. By return, Arduino send back the State (On/Off)
Init_Block
My problem now is to keep the SMS return to act on API :


It never acts!

Another way to explore, my smartphone is a Samsung Galaxy A8 (2018), with an Android version 9. The security software version is: ASKS V3.11, ADP V3.0 and SMR from May 2021 Release 1. Do I have to set parameters for applications to receive SMS?

Hello @Stevejg, the NTWD application does not work on my smartphone, I send an SMS to myself, NTWD is open, nothing happens! I have the message in the SMS received but the app does not respond. I must have a bad setup on the phone!

Hi @Vidalv,
but the SMS text received from your Arduino shouldn't be contained into "messageText" (and not into Texting1) ?
Cheers

Hello @uskiara,
To simplify I try the following basic :


You have to change with the correct phone number !
It seems the If get messageText = "On" is not correct, each time I get the answer to the button "System Off"
The code :
SMS_Return.aia (2,6 Ko)

In some versions of Android, the SMS permission is turned on by default. In other versions, this permission is turned off by default. To set the app's permission on a device for the SMS app, choose Settings > Apps > SMS Messaging > Permissions, and turn on the SMS permission for the app.

The attached simplified SMS_Texting .aia (5.0 KB) SMS app (no LocationSensor etc) responds to Text messages in the app on an Android 4.2 cell when the apk is installed.

The Texting app may work in your Android 9. You may have to turn on the SMS permission manually as described above. Sorry, not having another cell phone to test I don't know whether it will work. Try the aia. Does it work?

Hi @SteveJG, I tested the API and I have a message to launch: Error 908: The permission has been denied. Please enable it in the Setting app. For this App the settings is :


What can I do more ?

Sorry, I don't know. One way would be to use the ask for permissions Block. I can't test that since my 4.2 provides the permissions automatically nor do I know what permission would have to be requested. You could also manually set the Telephone permissions in Settings. Just a wild guess.

Perhaps Android 9 breaks the Texting component even using the Send Message Direct Block. @Anke or @ewpatton might know how to add the required permission for your Android in the app.

As a work around, I suggest you use the SendMessage Block to see if that makes a difference. This means instead of sending direct, you should be able to send the email manually. Then cross you fingers to see if you get a response.

So, finally, I found a way to talk about Arduino and app. Here the minimum code that I use to work:


Here AIA file :
SMS_Return.aia (3,1 Ko)
Many mistakes on my side, and the most important thing is that the Arduino sends SMS with a 'CRLF' or "\ n", that you must add to be able to compare strings! Without this impossible to debug something ... Good to know! Thank you all for your support.

Hello @Vidalv,
so, I see that you followed my suggestion to get the SMS contents by reading the messageText instead of the Texting1. Nice.
Another hint that I can suggest is to use the block "contains text upcase piece" instead of using the block "compare text". With this "escamotage" you don't need to have the two texts to be completely equal (comprehensive of \n\l). Normally I use this trick to allow a more "flexible" behaviour, including the case in which you have to handle both upper and lowercase words.
Last but not least remember that if you have to handle numbers, they can be letters of cyphers; for example :"message deux" or "message 2" (this often happens when you parse a string received by the SpeechRecognizer).
Bonne chance et meilleures salutations.
Ugo.

Hi @uskiara thanks for suggestions, at this time return SMS from Arduino are only short word, "On", "Off" and so on, that's the reason I use most simplest "Compare Texts".
Use of "contains any Text piece" seems, for me, more complex, I try this but I get an error :


Any idea ?
Thanks.

Salut @vidalv,
je suis en accord avec toi, le SMS envoyé par ton Arduino est très simple. Mais si tu veux recevoir quelque chose de plus "compliqué"...:slight_smile: tu peux utiliser un truc comme celui-ci:

Definitely agreed: the SMS sent by your Arduino is quite simple, but whether you want to receive something more "complicated" you could use something like:

image
A bientot,
Cheers,
Ugo.

1 Like

Thanks @uskiara for example. I am at the beginning of use AI2 and discover the syntax of this code. In the Arduino prototype there are multiple areas with specific actions, for the moment I analyse the message manually, but with an App it becomes more complicated. Does it exit a function that extracts a "keyword" of a sentence? Like receiving SMS with: "State On, Heat On, Water Off, Pump Off" ? I see there is a TinyDB is it easy to use or I'm on wrong way ?