Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

[Android] Allow to set notification's priority, visibility and importance options #854

Merged
merged 7 commits into from
Sep 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ PushNotification.localNotification({
tag: 'some_tag', // (optional) add tag to message
group: "group", // (optional) add group to message
ongoing: false, // (optional) set whether this is an "ongoing" notification
priority: "high", // (optional) set notification priority, default: high
visibility: "private", // (optional) set notification visibility, default: private
importance: "high", // (optional) set notification importance, default: high

/* iOS only properties */
alertAction: // (optional) default: view
Expand Down Expand Up @@ -295,6 +298,49 @@ PushNotification.localNotification({
PushNotification.cancelLocalNotifications({id: '123'});
```


## Notification priority ##

(optional) Specify `priority` to set priority of notification. Default value: "high"

Available options:

"max" = NotficationCompat.PRIORITY_MAX
"high" = NotficationCompat.PRIORITY_HIGH
"low" = NotficationCompat.PRIORITY_LOW
"min" = NotficationCompat.PRIORITY_MIN
"default" = NotficationCompat.PRIORITY_DEFAULT

More information: https://developer.android.com/reference/android/app/Notification.html#PRIORITY_DEFAULT

## Notification visibility ##

(optional) Specify `visibility` to set visibility of notification. Default value: "private"

Available options:

"private" = NotficationCompat.VISIBILITY_PRIVATE
"public" = NotficationCompat.VISIBILITY_PUBLIC
"secret" = NotficationCompat.VISIBILITY_SECRET

More information: https://developer.android.com/reference/android/app/Notification.html#VISIBILITY_PRIVATE

## Notification importance ##

(optional) Specify `importance` to set importance of notification. Default value: "high"

Available options:

"default" = NotificationManager.IMPORTANCE_DEFAULT
"max" = NotificationManager.IMPORTANCE_MAX
"high" = NotificationManager.IMPORTANCE_HIGH
"low" = NotificationManager.IMPORTANCE_LOW
"min" = NotificationManager.IMPORTANCE_MIN
"none" = NotificationManager.IMPORTANCE_NONE
"unspecified" = NotificationManager.IMPORTANCE_UNSPECIFIED

More information: https://developer.android.com/reference/android/app/NotificationManager#IMPORTANCE_DEFAULT

#### IOS
The `userInfo` parameter for `PushNotification.localNotification` is required for this operation and must contain an `id` parameter. The id supplied will then be used for the cancel operation.
```javascript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,55 @@ public void sendToNotificationCentre(Bundle bundle) {
title = context.getPackageManager().getApplicationLabel(appInfo).toString();
}

int priority = NotificationCompat.PRIORITY_HIGH;
final String priorityString = bundle.getString("priority");

if (priorityString != null) {
switch(priorityString.toLowerCase()) {
case "max":
priority = NotificationCompat.PRIORITY_MAX;
break;
case "high":
priority = NotificationCompat.PRIORITY_HIGH;
break;
case "low":
priority = NotificationCompat.PRIORITY_LOW;
break;
case "min":
priority = NotificationCompat.PRIORITY_MIN;
break;
case "default":
priority = NotificationCompat.PRIORITY_DEFAULT;
break;
default:
priority = NotificationCompat.PRIORITY_HIGH;
}
}

int visibility = NotificationCompat.VISIBILITY_PRIVATE;
final String visibilityString = bundle.getString("visibility");

if (visibilityString != null) {
switch(visibilityString.toLowerCase()) {
case "private":
visibility = NotificationCompat.VISIBILITY_PRIVATE;
break;
case "public":
visibility = NotificationCompat.VISIBILITY_PUBLIC;
break;
case "secret":
visibility = NotificationCompat.VISIBILITY_SECRET;
break;
default:
visibility = NotificationCompat.VISIBILITY_PRIVATE;
}
}

NotificationCompat.Builder notification = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID)
.setContentTitle(title)
.setTicker(bundle.getString("ticker"))
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setVisibility(visibility)
.setPriority(priority)
.setAutoCancel(bundle.getBoolean("autoCancel", true));

String group = bundle.getString("group");
Expand Down Expand Up @@ -492,7 +536,39 @@ private void checkOrCreateChannel(NotificationManager manager) {
if (manager == null)
return;

int importance = NotificationManager.IMPORTANCE_DEFAULT;
Bundle bundle = new Bundle();

int importance = NotificationManager.IMPORTANCE_HIGH;
final String importanceString = bundle.getString("importance");

if (importanceString != null) {
switch(importanceString.toLowerCase()) {
case "default":
importance = NotificationManager.IMPORTANCE_DEFAULT;
break;
case "max":
importance = NotificationManager.IMPORTANCE_MAX;
break;
case "high":
importance = NotificationManager.IMPORTANCE_HIGH;
break;
case "low":
importance = NotificationManager.IMPORTANCE_LOW;
break;
case "min":
importance = NotificationManager.IMPORTANCE_MIN;
break;
case "none":
importance = NotificationManager.IMPORTANCE_NONE;
break;
case "unspecified":
importance = NotificationManager.IMPORTANCE_UNSPECIFIED;
break;
default:
importance = NotificationManager.IMPORTANCE_HIGH;
}
}

NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, this.config.getChannelName(), importance);
channel.setDescription(this.config.getChannelDescription());
channel.enableLights(true);
Expand Down