App Inventor Extensions


Alarm Manager Extension
with Notification or Autostart

See the App Inventor Extensions document about how to use an App Inventor Extension.

For questions about this extension or bug reports please start a new thread in the App Inventor community. Thank you.

For feature requests please contact me by email. To be a sponsor of a new method already is possible starting from only 10 USD! With your contribution you will help the complete App Inventor community. Thank you.

Oct 30th, 2020: Version 1: initial version for App Inventor. This extension does not work in Kodular, because Kodular still does not support AndroidX libraries.

Nov 3rd, 2020: Version 2: bugfixes, alarms now will be reinitialized after rebooting the device, new methods GetAlarms, OpenNotificationSettings, intensive tests using devices starting rom Android 5 up to Android 11, Thank you Anke!

Nov 19rd, 2020: Version 3: new features repeat weekly, monthly, yearly added. AfterAlarm event added. Bugfix updating or cancelling an alarm. Now after an alarm (interval type ONCE) has been triggered it will be removed from database.Thank you Per por being the sponsor of version 3!

Nov 22th, 2020: Version 4: "bells and whistles" version: properties small icon, large icon, big picture, big text and color added

Jan 9th, 2021: Version 4a: bugfix registerForOnResume and registerForOnStop added

Jan 20th, 2021: Version 4b: minor improvement for multiple screen apps and the AfterAlarm event. For multiple screen apps the AfterAlarm Event will fire only for those screens, the extension is being used or has been dragged to the working area.

Feb 11th, 2021: Version 4c: BootService fixed for the 5 optional values (smallIcon, largeIcon, largeText, bigPicture, color), GetAllAlarms fixed. In case you are already have been using Version 4b in production and you still get an error after using GetAllAlarms in version 4c then please contact me by email. Thank you.

Oct 1st, 2021: Version 5: Autostart property added including the methods HasAppearOnTopPermission and OpenAppearOnTopSettings. Thank you Henry for being the sponsor of version 5!

Dec 28th, 2021: Version 5a: bug fix for Kodular: class name issue to start app after notification click

Aug 16th, 2022: Version 5b: SDK31 update(1): exported = "true" added in manifest for broadcast receivers

Sep 26th, 2022: Version 5c: SDK31 update(2): pending intent FLAG_IMMUTABLE, permission SCHEDULE_EXACT_ALARM added

Oct 21th, 2022: Version 5d: SDK31 update(3): pending intent FLAG_IMMUTABLE for BootService added

Nov 10th, 2022: Version 6: new method StartAtBoot to trigger a notification or autostart the app at boot time

May 10th, 2023: Version 7: SDK33 update: HasPostNotificationsPermission method added, permission android.permission.POST_NOTIFICATIONS added in Manifest

Sep 26th, 2023: Extension rebuilt to avoid "ERROR: DX returned an error code" for projects, having 2 extensions or more which use proguard to obfuscate their code, see also Pull request 3004.

Description

Alarm Manager Extension to send a notification or autostart the app at a given time or at boot time only once or repeated by an interval. In case autostart=false then after clicking the notification your app will be started. You can define a start text, which will be passed to your app in method 'get plain start text' and trigger some action after your app is started. Also of course works if your app is not running. The defined alarms will be reinitialized after rebooting the device. You also can define several alarms, just use a different id for each alarm.
Minimum API level is 21 (Android 5).
Required permissions: android.permission.RECEIVE_BOOT_COMPLETED, android.permission.FOREGROUND_SERVICE,
android.permission.SYSTEM_ALERT_WINDOW (added in version 5), android.permission.SCHEDULE_EXACT_ALARM (added in version 5c), android.permission.POST_NOTIFICATIONS (added in version 7)

Kodular Restrictions

Properties


Returns whether app should autostart.


Specifies whether app should autostart. Default value is False.

Note 1: To use this feature, the user needs to grant "Appear On Top" permission. See the new methods HasAppearOnTopPermission and OpenAppearOnTopSettings. So while the user is using another app, at a given time your app will get priority and will appear on top of the other currently running app.

Note 2: To be able to autostart the app at a given time make sure to close the app using the close application block, else the app will not start, because it is already running.

Note 3: For security reasons it is not possible to bring the app to the front in case the screen is locked. You first will have to unlock the screen. Please test the example app to see how you can do it. At the alarm time the app will be started automatically and a looping sound is played. If the screen is locked, you first have to unlock the screen to stop the sound.


Returns SmallIcon for notification. Recommended size is 96x96.


Sets SmallIcon for notification. Recommended size is 96x96.
Note: this feature is available starting rom Android 6 (API Level 23). For older devices this setting will be ignored. The small icon must be in png format and have a transparent background.


Returns LargeIcon for notification. Recommended size is 256x256.


Sets LargeIcon for notification. Recommended size is 256x256.
Note: this feature is available starting rom Android 6 (API Level 23). For older devices the application icon will be used as large icon.


Returns BigText for notification


Sets BigText for notification
Note: you can only use bigPicture or bigText. If you specify both, then only bigText will be displayed.


Returns BigPicture for notification. Minimum: 512x256, Balanced: 1024x512, Maximum: 2048x1024.


Sets BigPicture for notification. Minimum: 512x256, Balanced: 1024x512, Maximum: 2048x1024.
Note: you can only use bigPicture or bigText. If you specify both, then only bigText will be displayed.


Returns the notification color, i.e. the color as an alpha-red-green-blue integer.


Specifies the notification color. Note: you can use any integer color code or the color blocks of App Inventor. In the example alarmmanager app I used a simplified version of Italo's color picker example, see also the example project "StatusBarColor blocks" in the tools extension documentation.

Screenshots of the new features in Version 4

small Icon and default color

small Icon, large Icon, yellow color and big Text

small Icon, large Icon and green color

small Icon, large Icon, blue color and big Picture

Note: These are screenshots taken from a Samsung Galaxy A51 device running Android 10. Depending on the Android version you will get slightly other results.

Methods


Returns true, if post notifications permission has been granted, else false. This permission is available starting from API 33.


This method is for alarms which only should fire once, but starting from Version 3 also for long term intervals. Start an alarm at a given date/time (instant). In case the time already has passed, the alarm will start asap. Define the title, text and start text of the notification. Interval can be one of the following values: 'ONCE', 'WEEK', 'MONTH', 'YEAR'. The start text is the value which will be passed to your app in method 'get plain start text'. Use your own id (integer value). If you use the same id again, then the previously defined alarm, which already uses that id will be overwritten..

Note: The Start method uses setExact (Android documentation).

Note: You might want to check, if your app has post notifications permission using the new method HasPostNotificationsPermission.

Note: You will have to build the app to be able to test this method.


Start a repeating alarm at a given hour and minute (short term intervals). Define the title, text and start text of the notification. Interval can be one of the following values: 'FIFTEEN_MINUTES', 'HALF_HOUR', 'HOUR', 'HALF_DAY', 'DAY' The start text is the value which will be passed to your app in parameter 'get plain start text'. Use your own id (integer value). If you use the same id again, then the previously defined alarm, which already uses that id will be overwritten.

Note: The StartRepeating method uses setRepeating (Android documentation).

Note: You might want to check, if your app has post notifications permission using the new method HasPostNotificationsPermission.

Note: You will have to build the app to be able to test this method.


Start an alarm at boot time.
The start text is the value which will be passed to your app in method 'get plain start text'. Use your own id (integer value). If you use the same id again, then the previously defined alarm, which already uses that id will be overwritten."

Note: You will have to build the app to be able to test this method.


Return a list of all alarm Ids.


Retrieve the alarm in JSON format stored under the given id. If there's no such id, then return empty string.


Get all Alarms in JSON format.


Cancel an alarm using the id you previously used to start the alarm.


Open Notification Settings.


If user likes to autostart the app, special permission is required, Using this method, you can check, if the permission has been granted.


Open Appear On Top Settings to enable Autostart for app.

Until Android 10 the user can enable the Appear On Top setting directly after using the Open Appear On Top Settings method.

Starting from Android 11 you first have to select your app ...

... before you can enable the Appear On Top setting.

Events


Event returning success or failure after starting an alarm.


Event returning success or failure after canceling an alarm.


Event indicating that an alarm occurred. Event will fire only if the app is up and running, else a notification will be displayed. For multiple screen apps this happens only for those screens, the extension is being used or has been dragged to the working area.

Example App "Alarm Manager with Notification Test"


Screenshots:





Example App "Alarm Manager with Autostart Test"

For security reasons it is not possible to bring the app to the front in case the screen is locked. You first will have to unlock the screen. Please test the example app to see how you can do it. At the alarm time the app will be started automatically and a looping sound is played. If the screen is locked, you first have to unlock the screen to stop the sound.

Example App "Picture Of The Day": get daily at a given time the Astromomic picture of the day by the NASA APOD API.


Screenshots:






Test

Tested successfully on several devices starting from Android 5 up to Android 13. Additionally the example app has been built on the SDK33 App Inventor test server and tested successfully on Samsung Galaxy A54 running Android 13.

Questions and Answers

Q1: What is the difference between this Notification extension and others, which are also available in the community?
A: Generally my extension works starting from Android 5 up to the latest version Android 12. It is working even if the app is not running and the notification still will be sent at the defined date and time after rebooting the device. It does not need any further service like One Signal.

There are currently the following notification extensions available:

 

Q2: Woud it be possible to add a feature to the extension to restart my app at a defined date and time in the future?
A: This is now possible starting with version 5. However Google restricts this feature like this (taken from here): Android 10 (API level 29) and higher place restrictions on when apps can start activities when the app is running in the background. These restrictions help minimize interruptions for the user and keep the user more in control of what's shown on their screen. In nearly all cases, apps that are in the background should display time-sensitive notifications to provide urgent information to the user instead of directly starting an activity.
Also starting from Android 10 the app must have been granted the SYSTEM_ALERT_WINDOW permission by the user to be able to restart itself from the background. And in Android 11 this has been even restricted further.
For security reasons it is not possible to bring the app to the front in case the screen is locked. You first will have to unlock the screen.

Q3: I'm using a Xiaomi device and the alarm does not work anymore after rebooting the device. What can I do?
A: After rebooting the device, the Boot Service must reconfigure the alarms. However on Xiaomi devices, Auto Start is disabled by default for all applications. See here how to enable it for your app. See also https://dontkillmyapp.com/xiaomi

Q4: How to get an instant of the 25th of the current month?
A: See my answer here.

Q5: How to initiate a specific screen after clicking on push notification?
A: You will have to use the Screen.Initialize event like this

   if not is empty get plain start text
   then open another screen "your screen name"

You can find the not block in the logic drawer, the is empty block in the text drawer and the get plain start text block in the controls drawer.

Q6: I am trying to send a text message using AfterAlarm method when app is on the forefront sms goes but it does not go when app is in the background or after phone restarts
Unfortunately this will not work. As mentioned in the description of the extension, the purpose of the alarmmanager extension is to send a notification at a given time only once or repeated by an interval. And as described in the documentation of the AfterAlarm event: Event will fire only if the app is up and running, else a notification will be displayed..
Starting from version 5 it is possible to autostart the app at a given time. However see also the Google restrictions in Question 2 above. For security reasons it is not possible to bring the app to the front in case the screen is locked. You first will have to unlock the screen.

Q6: I would like to start my app regularly to do something without user interaction. Is this possible using this extension?
A: This is only possible if the device is not locked. Therefore the alarmmanager extenison not really can be used for this use case. You might want to try the Itoo Background Tasks Extension by Kumaraswamy_B.G to run app in the background.

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

Test the functionality of the Alarm Manager with Notification extension

Both test apps are available in Google Play. You can test the extension following these steps

  1. Follow the opt-in URL for the alarmmanager example app to get access to the app and to be able to download it to your device. Here you can test all the features.
  2. Follow the opt-in URL for the Picture Of The Day example app to get access to the app and to be able to download it to your device.
  3. Follow the opt-in URL for the Autostart example app to get access to the app and to be able to download it to your device.
  4. Start testing.

Buy the Alarm Manager extension for App Inventor


You can buy this extension (aix file).
With your payment you accept the terms and conditions below.

Payment options

1. Paypal

Please transfer 12 USD via Paypal
to Pura Vida Apps

2. Bitcoin

After having received your payment I will be happy to send the download link to you. Please let me know your Google account! I usually will send the download link not later than 24 hours after having received your payment.
Thank you! Taifun


Terms and Conditions

Back to top of page ...


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