diff --git a/docs/android_alarm_manager_plus/usage.mdx b/docs/android_alarm_manager_plus/usage.mdx index 35d3a85989..7cba9c52c2 100644 --- a/docs/android_alarm_manager_plus/usage.mdx +++ b/docs/android_alarm_manager_plus/usage.mdx @@ -4,13 +4,19 @@ sidebar_label: Usage hide_title: true --- -After importing this plugin to your project as usual, add the following to your -`AndroidManifest.xml` within the `` tags: +Before using the plugin you would also need a plugin to request [SCHEDULE_EXACT_ALARM](https://developer.android.com/reference/android/Manifest.permission#SCHEDULE_EXACT_ALARM) permission when your app targets Android 14 and newer. +Google introduced SCHEDULE_EXACT_ALARM permission in [Android 12](https://developer.android.com/about/versions/12/behavior-changes-12#exact-alarm-permission). In Android 13 it was granted by default. +Since Android 14 this permission [is denied by default](https://developer.android.com/about/versions/14/changes/schedule-exact-alarms) and apps need to ask user to provide it. +`android_alarm_manager_plus` does not provide a way to work with this permission, so be sure to handle such logic yourself. +To do so you would need an additional plugin, like [`permission_handler`](https://pub.dev/packages/permission_handler). + +After importing `android_alarm_manager_plus` plugin into your project, add the following lines to your +`AndroidManifest.xml` file inside `` tags: ```xml - + ``` @@ -39,7 +45,7 @@ Then in Dart code add: ```dart import 'package:android_alarm_manager_plus/android_alarm_manager_plus.dart'; -// Be sure to annotate your callback function to avoid issues in release mode on Flutter >= 3.3.0 +// It is required to annotate your callback function like this to avoid issues in release mode on Flutter >= 3.3.0 @pragma('vm:entry-point') void printHello() { final DateTime now = DateTime.now(); @@ -54,12 +60,16 @@ main() async { await AndroidAlarmManager.initialize(); runApp(...); final int helloAlarmID = 0; + + // Handle SCHEDULE_EXACT_ALARM permission before trying to schedule any alarm with the plugin + // Otherwise an exception will happen. Check Note below for more information + await AndroidAlarmManager.periodic(const Duration(minutes: 1), helloAlarmID, printHello); } ``` :::note -If your app has targetSDK=31 (Android 12) and you would like to create alarms with `alarmClock=true` or `exact=true` +If your app has targetSDK=31 (Android 12) or newer and you would like to create alarms with `alarmClock=true` or `exact=true` be aware that user or system might cancel such alarms by revoking `SCHEDULE_EXACT_ALARM` permission. More info can be found in [the official documentation](https://developer.android.com/training/scheduling/alarms#exact-permission-declare) diff --git a/packages/android_alarm_manager_plus/README.md b/packages/android_alarm_manager_plus/README.md index 69a4b213f6..88bf66a56e 100644 --- a/packages/android_alarm_manager_plus/README.md +++ b/packages/android_alarm_manager_plus/README.md @@ -6,7 +6,7 @@ [![pub points](https://img.shields.io/pub/points/android_alarm_manager_plus?color=2E8B57&label=pub%20points)](https://pub.dev/packages/android_alarm_manager_plus/score) [![android_alarm_manager_plus](https://github.com/fluttercommunity/plus_plugins/actions/workflows/android_alarm_manager_plus.yaml/badge.svg)](https://github.com/fluttercommunity/plus_plugins/actions/workflows/android_alarm_manager_plus.yaml) -
build
+
build
A Flutter plugin for accessing the Android AlarmManager service, and running Dart code in the background when alarms fire. @@ -19,13 +19,20 @@ Dart code in the background when alarms fire. ## Getting Started +> [!IMPORTANT] +> You would also need a plugin to request [SCHEDULE_EXACT_ALARM](https://developer.android.com/reference/android/Manifest.permission#SCHEDULE_EXACT_ALARM) permission if your app targets Android 14 and newer. +> Google introduced SCHEDULE_EXACT_ALARM permission in [Android 12](https://developer.android.com/about/versions/12/behavior-changes-12#exact-alarm-permission). In Android 13 it was granted by default. +> Since Android 14 this permission [is denied by default](https://developer.android.com/about/versions/14/changes/schedule-exact-alarms) and apps need to ask user to provide it. +> `android_alarm_manager_plus` does not provide a way to work with this permission, so be sure to handle such logic yourself. +> To do so you would need an additional plugin, like [`permission_handler`](https://pub.dev/packages/permission_handler). + After importing this plugin to your project as usual, add the following to your `AndroidManifest.xml` within the `` tags: ```xml - + ``` diff --git a/packages/android_alarm_manager_plus/lib/android_alarm_manager_plus.dart b/packages/android_alarm_manager_plus/lib/android_alarm_manager_plus.dart index 0831023a2c..1656dfda05 100644 --- a/packages/android_alarm_manager_plus/lib/android_alarm_manager_plus.dart +++ b/packages/android_alarm_manager_plus/lib/android_alarm_manager_plus.dart @@ -137,8 +137,8 @@ class AndroidAlarmManager { /// If `exact` is passed as `true`, the timer will be created with Android's /// `AlarmManagerCompat.setExact`. When `exact` is `false` (the default), the /// timer will be created with `AlarmManager.set`. - /// For apps with `targetSDK=31` before scheduling an exact alarm a check for - /// `SCHEDULE_EXACT_ALARM` permission is required. Otherwise, an exeption will + /// For apps with `targetSDK=31` and newer before scheduling an exact alarm a check for + /// `SCHEDULE_EXACT_ALARM` permission is required. Otherwise, an exception will /// be thrown and alarm won't schedule. /// /// If `wakeup` is passed as `true`, the device will be woken up when the @@ -207,7 +207,7 @@ class AndroidAlarmManager { /// If `exact` is passed as `true`, the timer will be created with Android's /// `AlarmManagerCompat.setExact`. When `exact` is `false` (the default), the /// timer will be created with `AlarmManager.set`. - /// For apps with `targetSDK=31` before scheduling an exact alarm a check for + /// For apps with `targetSDK=31` and newer before scheduling an exact alarm a check for /// `SCHEDULE_EXACT_ALARM` permission is required. Otherwise, an exception /// will be thrown and alarm won't schedule. /// @@ -290,8 +290,8 @@ class AndroidAlarmManager { /// If `exact` is passed as `true`, the timer will be created with Android's /// `AlarmManager.setRepeating`. When `exact` is `false` (the default), the /// timer will be created with `AlarmManager.setInexactRepeating`. - /// For apps with `targetSDK=31` before scheduling an exact alarm a check for - /// `SCHEDULE_EXACT_ALARM` permission is required. Otherwise, an exeption will + /// For apps with `targetSDK=31` and newer before scheduling an exact alarm a check for + /// `SCHEDULE_EXACT_ALARM` permission is required. Otherwise, an exception will /// be thrown and alarm won't schedule. /// /// If `wakeup` is passed as `true`, the device will be woken up when the