App Inventor Extensions


Alarm Manager with Notification Extension

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.

Description

Alarm Manager Extension to send a notification at a given time only once or repeated by an interval. 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

Note: This extension does not work in Kodular, because Kodular still does not support AndroidX libraries!

Properties


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


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 will have to build the app to be able to test the notifications.


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 will have to build the app to be able to test the notifications.


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.

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 Test"


Screenshots:





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

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 11 beta. 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: Theoretically this would be possible. However it is not recommended to do it. (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.

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.

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

Theoretically it would be possible to restart the app at a given time, however according to Google this is not recommended, see also 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 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. 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