[PAID] ⏰ Alarm Manager Extension with Notification or Autostart

Which one would be the latest version of the extension?

Well, Version 7b is currently the latest version, which can be found in the download folder, you can always find the latest version there

Taifun

The alarm is now playing, but it will not autostart.

Nevermind.

It looks like you found out meanwhile, that you first have to ask for Appear On Top permission, see also the autostart example project, the documentation at App Inventor Extensions: Alarm Manager | Pura Vida Apps and my answer from some days ago here

Taifun

Version 8 is now available.

Itoo integration

Thank you @Kumaraswamy for this amazing framework!

Itoo is a powerful framework to execute blocks in the background. Version 8 of the alarmmanager extension uses the new itoox-wrapper library and provides the new OnReceive event handler (which looks like a procedure). By default the event handler is located in Screen1. But you can set the property ReferenceScreen to use the event handler on a different screen.

The background event handler will be called from Itoo from the background after an alarm occurred. You will have to create the procedure using the name OnReceive. Also that procedure must have 3 arguments, else it will not work. Note: This background event handler also will be called if the app is in the foreground.

OnReceive

Now we can execute almost any logic in the background (no user interface components) after an alarm occurred and even define new alarms in the background. Please be aware, that there is no user interface available in the background.

Preconditions for using the OnReceive event handler together with Itoo

  • You should already have some experience in App Inventor and understand the basics. If you are new, then first learn App Inventor and come back later for these advances features. Alternatively you can contact me by email to get personal support for a small fee. As beginner you already can use the alarmmanager extension without the OnReceive event handler!
  • You are familiar with the Do it debugging functionality of App Inventor.
  • You are familiar with using Logcat. To find possible errors of your blocks in the background, let me suggest to filter the logcat output for the tags TaifunAlarmManager, Notifier, ItooCreator and System.err.

Guidelines for using Itoo

  • First get your background functionality running in the foreground. Like this, you can find errors much easier. And as soon as you got it working in the foreground, then test it in the background.
  • Read the complete Itoo to leaarn how Itoo works and try the example projects, See also the battery checker tutorial and notification listener and itoo tutorial.
  • Do not use global variables while in the background, use local variables instead
  • Do not use any user-visible or UI components in the background
  • In the background, use the Itoo StoreProperty/FetchProperty methods rather than TinyDB. TinyDB relies on SharedPreferences which will not ensure data synchronization across background processes.

Example use cases

  • Run a function when the alarm is activated and also set the next alarm without opening the screen or disrupting the user experience (requested by Tammi_Allen)
  • Send a text message after an alarm occurred
  • Do something regularly in the background or after booting the device.
  • Get daily prayer notifications (prayer times change from day to day) (requested by Chechnya_360)
Example project: Get a daily notification 30 minutes before sunset

Screenshot of the user interface (before and after starting)

Flowchart of the blocks logic
The procedures get and setAlarm will be called from the foreground and from the background.

Main Blocks


sunset2

sunset4

Helper procedures

  • tomorrow: Return tomorrows date in format YYYY-MM-DD
  • getSunset: Extract the sunset time from the returned JSON string and convert it into format YYYY-MM-DD HH:mm:ss
  • getInstantOfAlarmTime: Return the alarm time (for example sunset time minus 30 minutes) as instant
  • getNextAlarmTime: Extract the next alarm time from the stored alarm and convert it into format YYYY-MM-DD HH:mm:ss

More information including the documentation of 2 example projects at App Inventor Extensions: Alarm Manager | Pura Vida Apps

Taifun

1 Like

Is the alarm test app updated on the play store?
I downloaded the app, started the alarm, but only the notification is received in the foreground. In the background it is not received (nothing happens)
Xiaomi Android 11

For some devices you have to disable battery optimization, see also the discussion earlier in this thread [PAID] ⏰ Alarm Manager Extension with Notification or Autostart - #80 by Kumaraswamy

see also Q3 here App Inventor Extensions: Alarm Manager | Pura Vida Apps

See also

Taifun

I downloaded it from googleplay store to try it, but if I reboot the device the alarm goes off

Let's asume, as test you set an alarm in ten minutes, then you reboot the device. After rebooting and unlocking your device it takes a little bit of time until your device restarts all necessary services including the boot service of your app, in this case of the alarmmanager example app, which will set again all defined alarms.. After that your alarm will occur at the previously defined time.

If your alarm time meanwhile is in the past, then the notification will be displayed as soon as possible after reboot.

This feature is already available since version 2 of the app, i.e since November 2020. . meanwhile we are at version 8...

Taifun

Does it include audio?
The tests I did were for more than 10 minutes after that and I restarted immediately to see...

Now as soon as I set the alarm again after a half hour, I immediately rebooted and saw that the alarm I started had disappeared again.
I'll try one more time without rebooting

If you have questions, then please ask them in a way, others are able to understand them...

??
The notification will be displayed using your default notification sound
Make sure, the sound is not muted

Unclear what you are trying to tell us

Please explain in detail and make sure to not confuse yourself
Also after rebooting give your device a bit of time to start all services
If you define several alarms make sure to use another id for each alarm, else an existing alarm with the same id will be overwritten
You always can check, which alarms have been defined using the GetAllAlarns method

Taifun.

I have successfully tested the extension on dozens of devices (and all relevant Android versions). It works without any problems, even after restarting the device. Period.


Device name & Android version?

Sorry for my wrong expression, the time I gave to the application was half an hour

Yes android version

this is a Xiaomi device, isn't it? You have to disable battery optimization, see also Xiaomi | Don’t kill my app! , see also several posts in this thread about this, for example [PAID] ⏰ Alarm Manager Extension with Notification or Autostart - #82 by Kumaraswamy...

after diabling battery optimization then test again

  1. set an alarm
  2. check the GetAllAlarms result
  3. Reboot the device
  4. unlock the device and give the device some time to restart all services
  5. after that open the app and check again the GetAllAlarms result and the previously defined alarm should still be there

if it is not, then find the correct settings for your device, see again Xiaomi | Don’t kill my app! especially for MIUI 14

Autostart permission

On MIUI 14, there is a new permission to start from the background for each app, in Settings > Apps > Your app > App permissions > Background autostart.

Taifun

Unfortunately after the reboot the alarm still doesn't exist on my device

you have to find the correct settings for your device for this to work
Read again Xiaomi | Don’t kill my app!

Note: the settings of your device prevent the boot service of the extension from starting after booting the device. Adjust the settings of your device and after you found out what needs to be changed in your settings, let us know to help others with Xiaomi devices in future. Thank you..

Taifun

1 Like

@Carlo_Rotondo you deleted your question? It looks like you solved your issue yourself...

If you want to set several alarms, you have to choose another id for each alarm, else the previously set alarm will be overwritten

Also if the app is up and running at the alarm time, then event AfterAlarm will be triggered and no notification will be displayed, please also check the documentation.

For further questions don't hesitate to ask here...
Pura Vida!

Taifun