Recently, I have been doing some further development on Android App Inventor. My focus for this work was getting the application to send and receive SMS messages. To aid others in doing this I put together this tutorial which shows this.
The first part of the tutorial shows how to send an SMS from within an App Inventor App. This is relatively simple and requires a a couple of text boxes (Mobile Number & Message Text) and a button to press to send the message.
You will also need to add a non-visual Texting component to the form.
Once the form has been created, the Blocks required to send a message should be configured as in the following image.
This block of code is executed when the user clicks the Send Message button. The first two actions are to set the Mobile Number and Message text on the Texting object to the values in the text boxes.
The last action calls the Texting.SendMessage method to actually send an SMS. Simple.
Note: This code does not do any error checking or validation. Erroneous data may cause the application to Force Close.
The second part of the tutorial will show how to make an App Inventor application respond to an SMS that it receives. For this application there is no GUI as the application handles the logic in the background. All we need are some blocks to intercept the SMS messages received.
This block of code is executed when the phone gets a SMS message.
The MessageRecieved method exposes two values: number and messageText. You can store these in a couple of variables.
The second thing this block does is to check the message to see if it contains the text 'Status?' If this text is in the message it will create a new TextMessage using the received number and respond with the message 'All Good!'. This is a simple application for this but could be used for such things as responding with a user location or responding with a simple message if the user is unavailable.
I hope this tutorial has been helpful. Please feel free to comment if you need further information.
I have added a link to the source code here.
My other App Inventor tutorials:
App Inventor - Location Services
App Inventor - Lists
Try these 4 tips for easier last-minute shopping
2 weeks ago
Perfect... Works great the only thing I do not understand is how the Text Received Part works...
ReplyDelete@Markess - in this case the application will intercept any text message the phone received and check the contents of the SMS. If the content of the message is 'Status?' it will respond back to the other party with an SMS stating 'All Good'. The SMS is not changed or deleted. It remains in the phone memory.
ReplyDeleteOther uses may be to intercept all SMS from a particular phone number and treat them in a particular way. I hope this helps.
HI Dave, perhaps you can help me.
ReplyDeleteI'm New to App Inventer and have been following the Tutorials, but I'm stuck one one small thing.
I'm using the TEXTING function to communicate with an SMS Controller which I use to control stuff in my apartment.
I am struggling to get the received text (back from the SMS controller) to display in the App that I've created; It always displays in the toolbar at the top of the phone. Is it possible for the received text to be displayed in the App?
If so what blocks must I drag to enable this.
Cheers, K.
K. If the SMS controller is sending back an SMS what your are seeing is the incoming message notification. In my tutorial above I intercept these messages and check what the contents are. If the message matches 'Status?' it returns an SMS. Instead of this you can send the contents to a onscreen text box. Dave.
ReplyDeleteHi Dave.
DeleteA stupid question, but how do you do that, send the message to a onscreen box?
Ds
Ds, check out my latest tutorial. Hopefully, this will help you.
Deletehttp://coxydave.blogspot.com.au/2012/05/android-app-inventor-more-sms-services.html
thanks a lot!Before,I do not know how to recieve message.I should notify the user.
ReplyDeleteHello Dave,
ReplyDeleteDo you know if the App Inventor can access the existing SMS list (the SMS that received prior to launch the 'custom' app)
Hello, i want to send a message to a number through app inventor...i used these blocks but it says to me gerneric problem, the message is not sent...what can i do please???
ReplyDeletehello dave,
ReplyDeleteI'm New to App Inventor. is it possible to sent text from app inventor to phone
or any other suggestion..thanks^^