Catch message from SMS then application is not running and show it in notifier inside app

33 views
Skip to first unread message

Алексей Сергеев

unread,
Sep 20, 2019, 8:13:07 AM9/20/19
to MIT App Inventor Forum
Hi. I have an app which is uses Texting component to exchange messages with my device. I want my application to receive commands from sms even when it is minimized. But, even with the third mode* enabled in the Texting component, a notification simply displayes. Taping on this notification just opens my application. However, the application does not receive any data. Tell me, please, what is the best way to act in this case?

* 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.

blocks (1).png


SteveJG

unread,
Sep 20, 2019, 8:47:27 AM9/20/19
to mitappinv...@googlegroups.com
Hi Алексей,

App Inventor 2 apps cannot run in the background as a Service.  That apparently is what you want to do with your app.  .  To work around the limitation that makes it impossible for your app to run in the background, the best you can do is prevent your Android from going to sleep.  There is a simple way to keep the screen on to force the screen to Stay On.   That might work for you. Perhaps set ReceivingEnabled to 2?

Either use a Stay Awake block routine using a Notifier 
or you use Taifun's Tools Extension: https://puravidaapps.com/tools.php

Be aware using either an extension or a block routine drains your device battery rapidly.

If you use a Stay Awake solution, does your app work as you expect?   Are you using Companion 2.55 or 2.55u?   To automatically send sms messages, you need to use the 
lower Block which requires Companion 2.55u  .  Not needed if the sms is not originating with your app.

textmessage.PNG

Regards,
Steve

Алексей Сергеев

unread,
Sep 20, 2019, 10:44:58 AM9/20/19
to mitappinv...@googlegroups.com
Thanks. Sorry, but this does not fit. My application should have the function of receiving reports from another device at a specific time. There can be many devices and they differ only in their phone number. Puravida has an extension that reads SMS, but it reads all messages at once and I think this is a very long process. And this extension has compatibility issues.
Maybe you know about the ability to read SMS by phone number? Thus, I would be able to check the latest messages when starting the app.

SteveJG

unread,
Sep 20, 2019, 11:19:06 AM9/20/19
to MIT App Inventor Forum
You want "application should have the function of receiving reports from another device at a specific time."  OK, then you must use a Stay Awake routine to keep the Android device running in the foreground .  App Inventor 2 apps CAN NOT run in the background.

To do what you want to do, your App Inventor app must run continually in the foreground.

A solution?   Use a professional compiler like Android Studio or B4A or Delphi Community Edition that will allow your app to run in the background as a Service instead of App Inventor.

To read messages by phone number your Block code could be something like this (simpler code than you posted)

textingBynumber.PNG



If you do that,  your app probably must still be awake when you expect a response in order to execute any special instructions.  Why "and when the application is not running they will be queued and a notification displayed to the user. (option 3 for a response) might work.  The code in your Blocks will NOT execute unless the app is active because the text will be queued.

You have a lot of experimenting to do.  If you can save the message queue to a TinyDB  you might "be able to check the latest messages when starting the app by recalling the TinyDB.  Can that be done?   I don't know, possibly by loading the queue in the Screen1.Initialize block.  Experiment and let us know what you find.  It might not be possible.




Reply all
Reply to author
Forward
0 new messages