Skip to content

Commit c44e661

Browse files
Can't set priority for Android heads-up notification #114
1 parent 004ccd6 commit c44e661

File tree

6 files changed

+8
-4
lines changed

6 files changed

+8
-4
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ You can pass several options to this function, everything is optional:
107107
|`ongoing` |Default is (`false`). Set whether this is an `ongoing` notification. Ongoing notifications cannot be dismissed by the user, so your application must take care of canceling them. (**Android Only**) |
108108
|`channel` |Default is (`Channel`). Set the channel name for Android API >= 26, which is shown when the user longpresses a notification. (**Android Only**) |
109109
|`forceShowWhenInForeground` |Default is `false`. Set to `true` to always show the notification. Note that on iOS < 10 this is ignored (the notification is not shown), and on newer Androids it's currently ignored as well (the notification always shows, per platform default). |
110+
|`priority` |Default is `0`. Will override `forceShowWhenInForeground` if set. This can be set to `2` for Android "heads-up" notifications. See [#114](https://github.com/EddyVerbruggen/nativescript-local-notifications/issues/114) for details. |
110111
|`actions` |Add an array of `NotificationAction` objects (see below) to add buttons or text input to a notification. |
111112
|`notificationLed` |Enable the notification LED light on Android (if supported by the device), this can be either: `true` (if you want to use the default color), or a custom color for the notification LED light (if supported by the device). (**Android Only**). Default not set.|
112113

native-src/android/app/src/main/java/com/telerik/localnotifications/Builder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static Notification build(JSONObject options, Context context, int notificationI
6868
.setNumber(options.optInt("badge"))
6969
.setColor(options.optInt("color"))
7070
.setOngoing(options.optBoolean("ongoing"))
71-
.setPriority(options.optBoolean("forceShowWhenInForeground") ? 1 : 0)
71+
.setPriority(options.optInt("priority", options.optBoolean("forceShowWhenInForeground") ? 1 : 0))
7272
.setTicker(options.optString("ticker", null)); // Let the OS handle the default value for the ticker.
7373

7474
final Object thumbnail = options.opt("thumbnail");

src/local-notifications-common.ts

+2
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ export interface ScheduleOptions {
178178
*/
179179
forceShowWhenInForeground?: boolean;
180180

181+
priority?: number;
182+
181183
/**
182184
* Buttons or text input.
183185
*/

src/local-notifications.ios.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,9 @@ export class LocalNotificationsImpl extends LocalNotificationsCommon implements
136136
content.sound = UNNotificationSound.defaultSound;
137137
}
138138

139-
const userInfoDict = new NSMutableDictionary({capacity: 1});
139+
const userInfoDict = new NSMutableDictionary({capacity: 2});
140140
userInfoDict.setObjectForKey(options.forceShowWhenInForeground, "forceShowWhenInForeground");
141+
userInfoDict.setObjectForKey(options.priority, "priority");
141142
content.userInfo = userInfoDict;
142143

143144
// Notification trigger and repeat
@@ -524,7 +525,7 @@ class UNUserNotificationCenterDelegateImpl extends NSObject implements UNUserNot
524525

525526
this.receivedInForeground = true;
526527

527-
if (notification.request.content.userInfo.valueForKey("forceShowWhenInForeground")) {
528+
if (notification.request.content.userInfo.valueForKey("forceShowWhenInForeground") || notification.request.content.userInfo.valueForKey("priority")) {
528529
completionHandler(UNNotificationPresentationOptions.Badge | UNNotificationPresentationOptions.Sound | UNNotificationPresentationOptions.Alert);
529530
} else {
530531
completionHandler(UNNotificationPresentationOptions.Badge | UNNotificationPresentationOptions.Sound);

src/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-local-notifications",
3-
"version": "4.1.1",
3+
"version": "4.1.2",
44
"description": "The Local Notifications plugin allows your app to show notifications when the app is not running. Just like remote push notifications, but a few orders of magnitude easier to set up.",
55
"main": "local-notifications",
66
"typings": "index.d.ts",

src/platforms/android/app-release.aar

29 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)