diff --git a/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java b/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java index 57baec500..5cb1918d8 100644 --- a/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java +++ b/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java @@ -347,6 +347,12 @@ protected static Notification createNotification( builder.setUsesChronometer(notificationDetails.usesChronometer); } + if (notificationDetails.chronometerCountDown != null) { + if (VERSION.SDK_INT >= VERSION_CODES.N) { + builder.setChronometerCountDown(notificationDetails.chronometerCountDown); + } + } + if (BooleanUtils.getValue(notificationDetails.fullScreenIntent)) { builder.setFullScreenIntent(pendingIntent, true); } diff --git a/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/models/NotificationDetails.java b/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/models/NotificationDetails.java index 407939499..49c6d8dca 100644 --- a/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/models/NotificationDetails.java +++ b/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/models/NotificationDetails.java @@ -108,6 +108,7 @@ public class NotificationDetails implements Serializable { private static final String SHOW_WHEN = "showWhen"; private static final String WHEN = "when"; private static final String USES_CHRONOMETER = "usesChronometer"; + private static final String CHRONOMETER_COUNT_DOWN = "chronometerCountDown"; private static final String ADDITIONAL_FLAGS = "additionalFlags"; private static final String SCHEDULED_DATE_TIME = "scheduledDateTime"; @@ -173,6 +174,7 @@ public class NotificationDetails implements Serializable { public int[] additionalFlags; public Boolean showWhen; public Boolean usesChronometer; + public Boolean chronometerCountDown; public String scheduledDateTime; public String timeZoneName; public ScheduledNotificationRepeatFrequency scheduledNotificationRepeatFrequency; @@ -255,6 +257,8 @@ private static void readPlatformSpecifics( notificationDetails.when = LongUtils.parseLong(platformChannelSpecifics.get(WHEN)); notificationDetails.usesChronometer = (Boolean) platformChannelSpecifics.get(USES_CHRONOMETER); + notificationDetails.chronometerCountDown = + (Boolean) platformChannelSpecifics.get(CHRONOMETER_COUNT_DOWN); readProgressInformation(notificationDetails, platformChannelSpecifics); readColor(notificationDetails, platformChannelSpecifics); readChannelInformation(notificationDetails, platformChannelSpecifics); diff --git a/flutter_local_notifications/example/lib/main.dart b/flutter_local_notifications/example/lib/main.dart index 9fc849662..88ce9a378 100644 --- a/flutter_local_notifications/example/lib/main.dart +++ b/flutter_local_notifications/example/lib/main.dart @@ -2172,6 +2172,7 @@ class _HomePageState extends State { priority: Priority.high, when: DateTime.now().millisecondsSinceEpoch - 120 * 1000, usesChronometer: true, + chronometerCountDown: true, ); final NotificationDetails notificationDetails = NotificationDetails(android: androidNotificationDetails); diff --git a/flutter_local_notifications/lib/src/platform_specifics/android/method_channel_mappers.dart b/flutter_local_notifications/lib/src/platform_specifics/android/method_channel_mappers.dart index 9e533193f..f808d77b0 100644 --- a/flutter_local_notifications/lib/src/platform_specifics/android/method_channel_mappers.dart +++ b/flutter_local_notifications/lib/src/platform_specifics/android/method_channel_mappers.dart @@ -196,6 +196,7 @@ extension AndroidNotificationDetailsMapper on AndroidNotificationDetails { 'showWhen': showWhen, 'when': when, 'usesChronometer': usesChronometer, + 'chronometerCountDown': chronometerCountDown, 'showProgress': showProgress, 'maxProgress': maxProgress, 'progress': progress, diff --git a/flutter_local_notifications/lib/src/platform_specifics/android/notification_details.dart b/flutter_local_notifications/lib/src/platform_specifics/android/notification_details.dart index 46e1332fc..fd1a9746c 100644 --- a/flutter_local_notifications/lib/src/platform_specifics/android/notification_details.dart +++ b/flutter_local_notifications/lib/src/platform_specifics/android/notification_details.dart @@ -122,6 +122,7 @@ class AndroidNotificationDetails { this.showWhen = true, this.when, this.usesChronometer = false, + this.chronometerCountDown = false, this.channelShowBadge = true, this.showProgress = false, this.maxProgress = 0, @@ -274,6 +275,11 @@ class AndroidNotificationDetails { /// Useful when showing an elapsed time (like an ongoing phone call). final bool usesChronometer; + /// Sets the chronometer to count down instead of counting up. + /// + /// This property is only applicable to Android 7.0 and newer versions. + final bool chronometerCountDown; + /// Specifies if the notification will be used to show progress. final bool showProgress; diff --git a/flutter_local_notifications/test/android_flutter_local_notifications_test.dart b/flutter_local_notifications/test/android_flutter_local_notifications_test.dart index deb067627..7cdfa04cd 100644 --- a/flutter_local_notifications/test/android_flutter_local_notifications_test.dart +++ b/flutter_local_notifications/test/android_flutter_local_notifications_test.dart @@ -147,6 +147,7 @@ void main() { 'showWhen': true, 'when': null, 'usesChronometer': false, + 'chronometerCountDown': false, 'showProgress': false, 'maxProgress': 0, 'progress': 0, @@ -267,6 +268,7 @@ void main() { 'showWhen': true, 'when': null, 'usesChronometer': false, + 'chronometerCountDown': false, 'showProgress': false, 'maxProgress': 0, 'progress': 0, @@ -349,6 +351,7 @@ void main() { 'showWhen': true, 'when': null, 'usesChronometer': false, + 'chronometerCountDown': false, 'showProgress': false, 'maxProgress': 0, 'progress': 0, @@ -432,6 +435,7 @@ void main() { 'showWhen': true, 'when': timestamp, 'usesChronometer': false, + 'chronometerCountDown': false, 'showProgress': false, 'maxProgress': 0, 'progress': 0, @@ -516,6 +520,7 @@ void main() { 'showWhen': true, 'when': timestamp, 'usesChronometer': true, + 'chronometerCountDown': false, 'showProgress': false, 'maxProgress': 0, 'progress': 0, @@ -604,6 +609,7 @@ void main() { 'showWhen': true, 'when': null, 'usesChronometer': false, + 'chronometerCountDown': false, 'showProgress': false, 'maxProgress': 0, 'progress': 0, @@ -691,6 +697,7 @@ void main() { 'showWhen': true, 'when': null, 'usesChronometer': false, + 'chronometerCountDown': false, 'showProgress': false, 'maxProgress': 0, 'progress': 0, @@ -777,6 +784,7 @@ void main() { 'showWhen': true, 'when': null, 'usesChronometer': false, + 'chronometerCountDown': false, 'showProgress': false, 'maxProgress': 0, 'progress': 0, @@ -865,6 +873,7 @@ void main() { 'showWhen': true, 'when': null, 'usesChronometer': false, + 'chronometerCountDown': false, 'showProgress': false, 'maxProgress': 0, 'progress': 0, @@ -968,6 +977,7 @@ void main() { 'showWhen': true, 'when': null, 'usesChronometer': false, + 'chronometerCountDown': false, 'showProgress': false, 'maxProgress': 0, 'progress': 0, @@ -1065,6 +1075,7 @@ void main() { 'showWhen': true, 'when': null, 'usesChronometer': false, + 'chronometerCountDown': false, 'showProgress': false, 'maxProgress': 0, 'progress': 0, @@ -1168,6 +1179,7 @@ void main() { 'showWhen': true, 'when': null, 'usesChronometer': false, + 'chronometerCountDown': false, 'showProgress': false, 'maxProgress': 0, 'progress': 0, @@ -1263,6 +1275,7 @@ void main() { 'showWhen': true, 'when': null, 'usesChronometer': false, + 'chronometerCountDown': false, 'showProgress': false, 'maxProgress': 0, 'progress': 0, @@ -1362,6 +1375,7 @@ void main() { 'showWhen': true, 'when': null, 'usesChronometer': false, + 'chronometerCountDown': false, 'showProgress': false, 'maxProgress': 0, 'progress': 0, @@ -1452,6 +1466,7 @@ void main() { 'showWhen': true, 'when': null, 'usesChronometer': false, + 'chronometerCountDown': false, 'showProgress': false, 'maxProgress': 0, 'progress': 0, @@ -1539,6 +1554,7 @@ void main() { 'showWhen': true, 'when': null, 'usesChronometer': false, + 'chronometerCountDown': false, 'showProgress': false, 'maxProgress': 0, 'progress': 0, @@ -1633,6 +1649,7 @@ void main() { 'showWhen': true, 'when': null, 'usesChronometer': false, + 'chronometerCountDown': false, 'showProgress': false, 'maxProgress': 0, 'progress': 0, @@ -1756,6 +1773,7 @@ void main() { 'showWhen': true, 'when': null, 'usesChronometer': false, + 'chronometerCountDown': false, 'showProgress': false, 'maxProgress': 0, 'progress': 0, @@ -1867,6 +1885,7 @@ void main() { 'showWhen': true, 'when': null, 'usesChronometer': false, + 'chronometerCountDown': false, 'showProgress': false, 'maxProgress': 0, 'progress': 0, @@ -1962,6 +1981,7 @@ void main() { 'showWhen': true, 'when': null, 'usesChronometer': false, + 'chronometerCountDown': false, 'showProgress': false, 'maxProgress': 0, 'progress': 0, @@ -2056,6 +2076,7 @@ void main() { 'showWhen': true, 'when': null, 'usesChronometer': false, + 'chronometerCountDown': false, 'showProgress': false, 'maxProgress': 0, 'progress': 0, @@ -2151,6 +2172,7 @@ void main() { 'showWhen': true, 'when': null, 'usesChronometer': false, + 'chronometerCountDown': false, 'showProgress': false, 'maxProgress': 0, 'progress': 0, @@ -2444,6 +2466,7 @@ void main() { 'showWhen': true, 'when': null, 'usesChronometer': false, + 'chronometerCountDown': false, 'showProgress': false, 'maxProgress': 0, 'progress': 0,