The application has stopped receiving text messages in the background

Hi all!
About 2 years ago I made an application that receives text messages (and selects the relevant fragments from it). Everything worked ok. Recently I had to make small changes and now the application does not receive text messages when it does not work in the foreground. ReceivingEnabled = 3! Can anyone know or guess where the problem is. Or is it possible to “compile” aia file in the old version of App Inventor?
Any help/advice is welcomed,
Greg

http://ai2.appinventor.mit.edu/reference/components/social.html#Texting

Were you prompted to grant permission that the app will manage your text messages? This should be asked due to ReceivingEnabled being set to 3, but if you weren’t prompted then the functionality won’t work. You should also be able to grant the permission via the Settings app by finding your app and enabling the texting permissions.

Thank you for the ideas but they didn’t solve the problem.
It seems to me that I know the operation of the elements used to create the application, all the more so because the application worked correctly before!
During installation, the system asked for permission to receive SMSs. When the application is in the foreground, it works properly! The problem is when it is running in the background. When the application was “compiled” in the old version of the app inventer, these were not there problems.
Does anyone have any idea how to restore the application to work earlier?

A stayawake routine might allow you to set ReceivingEnabled properties to 2 instead of 3 . The app will ‘run’ constantly , especially if you keep your device’s charger plugged in. The app will not go to sleep while stayawake runs so ReceivingEnabled Foreground (2) should work fine instead of Always (3) and will receive all text messages. Experiment to see what works for you. I agree, option does not appear to be working like it did prior to Google (and phone providers) changing how they handle sms messages. I expect that is partially because how some phone providers handle queued sms messages but I do not know. I do know is option 3 does not work exactly as advertised in the documentation.

Here is how you might code a Stay Awake block routine using a Notifier

or you could use Taifun’s Tools Extension: https://puravidaapps.com/tools.php

Using either an extension or a block routine drains your device battery rapidly . These work around methods are not running the app in the Background, they force the app
screen to stay open .

Google changed how texting is allowed to work in Android in late 2018. The old ways do not work. When I set ReceivingEnabled to 3 it seems to work sometimes, sometimes it does not. When it is working and sends messages from queued messages, it is very annoying so it requires disabling the feature prior to allowing your app to go to sleep. When that happens for me, it creates issues. This is what the documentation says ... When a message arrives, the MessageReceived event is raised and provides the sending number and message. An app that includes this component will receive messages even when it is in the background (i.e. when it’s not visible on the screen) and, moreso, even if the app is not running, so long as it’s installed on the phone. If the phone receives a text message when the app is not in the foreground, the phone will show a notification in the notification bar. Selecting the notification will bring up the app. As an app developer, you’ll probably want to give your users the ability to control ReceivingEnabled so that they can make the phone ignore text messages. I expect for most users, this is unacceptable behavior.

The documentation says with regard to Texting

ReceivingEnabled If set to 1 (OFF) no messages will be received. If set to 2 (FOREGROUND) or 3 (ALWAYS) the component will respond to messages if it is running. In the case of 2 (FOREGROUND), messages received while the app is not running are discarded. In the case of 3 (ALWAYS), messages receive while the app is not running will show a notification. Selecting the notification will bring up the app and signal the MessageReceived event. Messages received when the app is dormant will be queued, and so several MessageReceived events might appear when the app awakens. As an app developer, it would be a good idea to give your users control over this property, so they can make their phones ignore text messages when your app is installed.

Might appear is the issue. , you are not getting them and I get them erratically. So, I would not use the sms for anything other than option 2 and be happy.

You didn't share your code that used to work or tell us whether you are compiling using the Companion with a " u " in its version.

@ewpatton ..1. shouldn't that gem be in the documentation? 2. Option 3 does not work as advertised. Have you tried it?

Regards,
Steve

I apologize for the absence of several days - I was busy with another project.
I tested the application with both ReceivingEnabled = 3 and 2. It did not change its operation. Similarly with Taifun’s Tools Extension: KeepScreenOn, the application does not work correctly.
I can describe exactly the main operation of the application. The application analyzes the content of the received SMS and if it finds the relevant parts of the text - plays previously prepared sound files informing the user by voice about the event. The application works on an watch (smartwatch) with an adroid (ver. QW - truncated android version, build version: 3.4.67). A clock without access to the internet and therefore deprived of the possibility of updating the system.
For the application be able to “run in the background”, I installed the MacroDroid program and created a macro in it that launches my program after every SMS received. My program then analyzes the content of the SMS and … I have already described it above.
At the moment when the application is in the front it works correctly in the background does not read received SMSes which is the main problem.
I did not attach the program code because the application is quite extensive and the part of the code itself responsible for receiving SMSs is literally a few elements. However, if it can help with something, I will gladly attach the code of the entire application or even do the second one with just receiving SMSs.
I don’t know what it means: “using the Companion with a” u “in its version”. Applications “compiles” at: http://ai2.appinventor.mit.edu. I also tried to import it into Koduar (https://creator.kodular.io/) and compile it there - it did not change the operation of the application. The problem is still not resolved.
Regards
Gregory

There are two versions of the Companion (currently 2.58a and 2.58u). The ' u ' versions allows you to build apps that use "dangerous permissions" , features Google does not allow on the PlayStore.
Using 2.58au allows you to use SendMessageDirect() Send a text message. Using this block will add dangerous permissions that will require additional approval if your app is submitted to the Google Play Store. ; Companion 2.58a only allows you to use SendMessage() Launch the phone’s default text messaging app with the message and phone number prepopulated.

These differences are described in Texting.

When you code the part that sends the text message, are you using SendmessageDirect or SendMessage? If using SendMessage, try using SendMessageeDirect (after installing the ' u ' Companion).

Most users find that using option 3 (Always) does not work properly at all. It might have something to do with their Android version, with how their cell service provider ques messages or something else.

thank you SteveJG for your answer.
I don’t know if I understood you correctly about the Companion version. The application installation file I “compile” directly on the AppInventor website and then I install the application directly on the device. I do so to be able to check its operation and cooperation with the MacroDroid application. I can’t change the version Companion in this way.
I will add that both the SendMessage () and SendMessageDirect () options appear in the “texting” module options. However, it does not matter, because in my application I only use the element: messageReceived (). The application does not send anything but only receives.
As I wrote earlier, the watch system could not change, so only the change in the program compilation remains. The same version of the application compiled 2 years ago works now ok. Compiled now not - does not receive sms when it is running in the background.
regards
Gregory

OK. This issue flagged for MIT...perhaps Evan can resolve it.


@ewpatton The Texting component continues to display issues when Setting ReceivingEnabled to option 3 (Always) Evan. It seems to work for some users and not for others. I have been speculating this might be to issues with the Android os installed on; issues with the cell service provider in how they handle queued messages, or possibly a bug introduced after Google changed policy... see Grzegorz's post.

Also, you earlier indicated

Perhaps that information can be added to the documentation.? The message does not appear on a 4.2.2 Android for what it is worth (pre dangerous permissions??). My experience is notifications for queued messages sometimes happened on my phone when I tested and sometimes not...so I have a similar experience as the several users who report issues with the ReceivingEnabled when set to option 3. No issues with option2.

-- Steve


Because the application that does not receive text messages is useless in my case, I wanted to ask again if there is anywhere the possibility of “compiling” the program in the old version of App Inventor.
That possibility would solve my problem.
regards
Gregory

Here old versions of App Inventor offline.

https://sourceforge.net/projects/ai2u/files/

Thank you very much for the link.
I downloaded the 4.6 version, I compiled and the application works again as expected. Cool!
Juan_Antonio thank you very much!
Regards
Gregory

This is exactly the issue i have been having, but i use a mac, so cannot download version 4.6 to fix it. Is there a mac version anywhere (or another known fix maybe)?
Thanks in advance
Steve

Hi, I'm having problems receiveing text messages too. I can see people saying we need to set "ReceivingEnabled" to 2 or 3, but where do I need to put it? I can see the ReceivingEnabled block, but it looks like it needs to be put inside something?

Welcome @Lee_Huacker

smsReceivingEnabled

(only use 2 or 3); it can be placed in a Screen1.Initialize event handler.

or

smsReceivingEnabled2

Please read Texting

Thank you @SteveJG ! I hadn't noticed there is a Screen1.Initialize event handler.

Here is what I have got from your suggestion:
Receiving Texts Texting Properties
I've also tried putting the same code inside a button.click code, and it works OK, so I think it is something to do with receiving messages, or maybe a setting on my phone or something, but when I check the settings on my phone for the app, receive text messages is included.

Any ideas? Thank you so much!

I tested on an Android 4.2 cell using a separate phone to send the text message. It worked fine using #2 (don't let the screen go to sleep). As I recall my app worked (captured messages) sometimes using #3. You tested with #3. Try again using #2 and see if you get a different result. The issue could be stuff related to your cell provider, your Android version etc. New Androids might get fussy with this feature as Google tightens security protocols and might not work in the background with some Android phones.

The documentation says:
ReceivingEnabled If set to 1 (OFF) no messages will be received. If set to 2 (FOREGROUND) or 3 (ALWAYS) the component will respond to messages if it is running. In the case of 2 (FOREGROUND), messages received while the app is not running are discarded. In the case of 3 (ALWAYS), messages receive while the app is not running will show a notification. Selecting the notification will bring up the app and signal the MessageReceived event. Messages received when the app is dormant will be queued, and so several MessageReceived events might appear when the app awakens. As an app developer, it would be a good idea to give your users control over this property, so they can make their phones ignore text messages when your app is installed.

Experiment with #2 and #3 and see if #2 works where #3 might not. Also try on a different phone.

Aw thank you for your suggestions! I didn't think to try #2. I did try after your suggestion though on my Pixel 2, and unfortunately it still didn't work. I will try again when I can borrow my dad's phone because he has a different phone to me.

Did you allow the screen to close? Option 2 will only work while the app is active. #2 does not work in the background.

If you still have issues, you might share your code if you use more than you already posted; you could have a coding issue. Sometimes a Notifier can cause issues; temporarily disable your Notifier block and try again?

Hi did you find a solution for your problem