How can I receive sms while mobile screen is off at specific battery level reached?

How can I build a Kodular application that reads the device battery percentage using a Battery Reader extension and automatically sends an SMS when the battery reaches a defined level, even when the screen is off or the app is in the background?

I’m specifically looking for guidance on background execution (screen off) and the correct way to trigger SMS at a set battery percentage.

Hi dear,

Welcome to the :kodular:odular community!

To make the app work in the background you’ll need to use iToo.

For sending the message, you could use the Texting component but who do you need to send the message to?
Otherwise, you can simply use the native notification component, or alternatively an extension.

Use the battery manager extension App Inventor Extensions: Battery Manager | Pura Vida Apps together with itoo and the texting component

Here are 2 examples to study

  1. check battery in background
    Battery checker reminding you to unplug when fully charged - Tutorials and Guides - MIT App Inventor Community

  2. send sms in background
    [PAID] ⏰ Alarm Manager Extension with Notification or Autostart - #247 by Taifun - Extensions - MIT App Inventor Community

Taifun

Q. For sending the message, you could use the Texting component but who do you need to send the message to?
Ans: to my defined mobile number.

i have already used a itoo extension without the specific battery %, but it can not able to send the message when the screen is off. means just send the simple message to the defined mobile number. I have tried to put that texting component in the same loop with the call player1.vibrate millisecond=500 and vibration is working but sms(texting) component is not working while screen is off.

Perfect, then the Texting component is required.

Can you confirm that, with the app open, your procedure works and sends the message correctly?

What about providing a screenshot of your relevant blocks?
And: did you ask for SEND_SMS permission?
Are you using the latest itoo version?

For debugging use logcat

Taifun

1 Like

Q1. What about providing a screenshot of your relevant blocks?
Ans. Blocks attached.
Q2. did you ask for SEND_SMS permission?
Ans. When i open the app for the 1st time after installation, it asks for the permission to send the sms. I granted that permission too.
Q3. Are you using the latest itoo version?
Ans. Yes. V4.4.2

if application is received any simple message like Hello etc. that message is also not reflected in the text box i.e. Received_ and also label is not getting updated i.e. Received.

You did not really understand how background processing works
Start reading the itoo thread from the beginning, try the simple examples, try the batterychecker example and learn from there

You only have to adjust the batterychecker example to your needs, i.e. repkace the text to speech component with sending the sms

Some observations

  1. create your process Notification only once.
  2. do not create a task
  3. do not use a timer, use the BatteryChanged event from the battery manager extension and as it runs in the background use an event handler, which looks like a procedure
  4. there exists no user interface in the background, i.e. the Notification. ShowAlert willl not work

You forgot to implement this logic completely

Taifun

Make sure to set ReceivingEnabled to Always

Receiving Enabled

If set to 1 (OFF) no messages will be received. If set to 2 (FOREGROUND) or3 (ALWAYS) the component will respond to messages if it is running. If the app is not running then the message will be discarded if set to 2 (FOREGROUND). If set to 3 (ALWAYS) and the app is not running the phone 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.

This will work only in the foreground. In the background the texting component can only display a notification. Remember: there is no user interface available in the background.

If you still do not get a notification then you forgot to ask for post notifications permission

To receive sms in the background and do something you could use the following extension

Taifun