App Inventor and Java


How to start an App Inventor app after a SMS has been received

Note: This project has been deprecated. It will not work anymore on newer Android devices because these devices require the permission android.permission.READ_SMS.

Having apps that can do things in the background has been one of the most asked for App Inventor features, see also issue 32.

After going through the different SMS Text tutorials you will realize, that they do not work anymore if the device is sleeping. The Google Voice intergration was a nice feature, see also the Alert Me tutorial, however this works only in the United States and not elsewhere in the world.

As workaround, I therefore put together a Java app SMS Receiver using parts of the source from here and a small App Inventor test project smstest.apk, which will be started after a SMS has been received.

Version History

  • Version 1

    • Initial version.
  • Version 2.x

    • Now you can configure the trigger text and the App Inventor app to be started.
    • The phone number of the sender will now be transferred to the App Inventor app.
  • Version 3

    • Now it is also possible to start the defined App Inventor app for all messages. To start the App Inventor app only if a trigger message has been received, this of course still works.
    • SMS Receiver will now acquire a wake lock for 1 minute, which means, in case the device is sleeping, it will wake up to be able to run the App Inventor app. Therefore additionally the permission System tools: prevent phone from sleeping is now required.
    • SMS Receiver now also will start the App Inventor app, if the phone is locked. Therefore additionally the permission System tools: disable keyguard is now required. However this has no effect while any DevicePolicyManager is enabled that requires a password.

How does it work?

Each time a SMS is received, SMS Receiver checks, if the App Inventor app needs to be started depending on the stored settings:

  • Start the defined App Inventor app for all messages
  • Start the defined App Inventor app only for trigger message

This also still works after rebooting the device. Thank you lisisoft.com for the app icon.


Some Notes:

  • This example works only, if the app SMS Receiver is installed on your device.
  • As Jos pointed out here: the app to be triggered will be opened also while you are in a game or in a phone call, this might be something you do not like.

Start App Inventor app for all messages

In the example the SMS with the message "Woo Hoo!" has been sent to the device. The phone number and message will be sent to the App Inventor app in the following format: <phone number>|||<message>. You will find that info in the "get plain start text" block.


LogCat after a message has been received


Start App Inventor app only for trigger message

In the example the trigger SMS has been sent to the device. Only the phone number will be sent to the App Inventor app in this case. You will find it in the "get plain start text" block.


LogCat after the trigger message has been received


LogCat after another message has been received

For questions about App Inventor,
please ask in the App Inventor forum.Thank you.

App Inventor blocks


Questions and Answers

Q1:Tried to run SMS Receiver on my Sony xperia z as I want to buy the live version to call my sms app - it keeps crashing.
A: Make sure to use the correct package name of your app like this: appinventor.ai_YOURLOGINNAME.YOURPROJECTNAME

You also can find out the package name like this: Download the source code of your App Inventor project to your computer. Using a file explorer or unzip utility, find the file called youngandroidproject/project.properties. The first line will start with "main=". Everything after that is the package and class name.

For example, here is a first line you might see for an App named HelloPurr: main=appinventor.ai_ElsaArendelle.HelloPurr.Screen1
The ElsaArendelle part of the name comes from the App Inventor user account. The package name in the example is appinventor.ai_ElsaArendelle.HelloPurr

Q2: I sent trigger text message "puravida" all worked as it should. Then I changed SMSReceiver to "start AppInventor app for all messages" and sent text message - SMS Test opens with blank screen. Is this correct?
A: Make sure to close your app before doing the test. The smstest app should display a notifier after a message has been received, see screenshots above.

Q3: I was wondering, does this work on AI2LiveComplete?
A: The SMS Receiver app can start any Android app, this can be a MIT App Inventor app, an AiLiveComplete App Inventor app or any other Android app developed with Eclipse or Android Studio or other development environments.

Q4: Is it possible to just start the app without the Phone noticing it got a sms? Just start the app in the background when the phone is asleep?
A: No, you default sms app will always receive the sms.

Download and Test with the test version of the SMS Receiver app

The test version of the SMS Receiver app will work for a while. After that, a message will be sent to the App Inventor app. You can continue using the test version of the SMS Receiver app after deleting its data.

Download App Inventor test project
Download test version of the SMS Receiver app

Back to top of page ...


Home | Snippets | Tutorials | Extensions | Links | Search | Privacy Policy | Contact