Skip to content
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
10 changes: 5 additions & 5 deletions push-notifications/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ From Android 8.0 (API level 26) and higher, notification channels are supported

You can configure the way the push notifications are displayed when the app is in foreground.

| Prop | Type | Description | Since |
| ------------------------- | --------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`presentationOptions`** | <code>PresentationOption[]</code> | This is an array of strings you can combine. Possible values in the array are: - `badge`: badge count on the app icon is updated (default value) - `sound`: the device will ring/vibrate when the push notification is received - `alert`: the push notification is displayed in a native dialog An empty array can be provided if none of the options are desired. badge is only available for iOS. | 1.0.0 |
| Prop | Type | Description | Since |
| ------------------------- | --------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`presentationOptions`** | <code>PresentationOption[]</code> | This is an array of strings you can combine. Possible values in the array are: - `badge`: badge count on the app icon is updated (default value) - `sound`: the device will ring/vibrate when the push notification is received - `alert`: **Deprecated on iOS.** Use `banner` and `list` instead. On Android, this value is still used to display the notification. - `banner`: the push notification is displayed as a banner - `list`: the push notification is displayed in the notification center An empty array can be provided if none of the options are desired. badge is only available for iOS. | 1.0.0 |

### Examples

Expand All @@ -99,7 +99,7 @@ In `capacitor.config.json`:
{
"plugins": {
"PushNotifications": {
"presentationOptions": ["badge", "sound", "alert"]
"presentationOptions": ["badge", "sound", "alert", "banner", "list"]
}
}
}
Expand All @@ -115,7 +115,7 @@ import { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = {
plugins: {
PushNotifications: {
presentationOptions: ["badge", "sound", "alert"],
presentationOptions: ["badge", "sound", "alert", "banner", "list"],
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.firebase.messaging.NotificationParams;
import com.google.firebase.messaging.RemoteMessage;
import java.util.Arrays;
import java.util.List;
import org.json.JSONException;
import org.json.JSONObject;

Expand Down Expand Up @@ -247,7 +248,8 @@ public void fireNotification(RemoteMessage remoteMessage) {
String body = notification.getBody();
String[] presentation = getConfig().getArray("presentationOptions");
if (presentation != null) {
if (Arrays.asList(presentation).contains("alert")) {
List<String> presentationList = Arrays.asList(presentation);
if (presentationList.contains("alert") || presentationList.contains("banner") || presentationList.contains("list")) {
Bundle bundle = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ public class PushNotificationsHandler: NSObject, NotificationHandlerProtocol {

optionsArray.forEach { option in
switch option {
case "banner":
presentationOptions.insert(.banner)
case "list":
presentationOptions.insert(.list)
case "alert":
presentationOptions.insert(.alert)
presentationOptions.insert(.banner)
presentationOptions.insert(.list)
case "badge":
presentationOptions.insert(.badge)

case "sound":
presentationOptions.insert(.sound)
default:
Expand Down
8 changes: 5 additions & 3 deletions push-notifications/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import type { PermissionState, PluginListenerHandle } from '@capacitor/core';

export type PresentationOption = 'badge' | 'sound' | 'alert';
export type PresentationOption = 'badge' | 'sound' | 'alert' | 'banner' | 'list';

declare module '@capacitor/cli' {
export interface PluginsConfig {
Expand All @@ -14,14 +14,16 @@ declare module '@capacitor/cli' {
* This is an array of strings you can combine. Possible values in the array are:
* - `badge`: badge count on the app icon is updated (default value)
* - `sound`: the device will ring/vibrate when the push notification is received
* - `alert`: the push notification is displayed in a native dialog
* - `alert`: **Deprecated on iOS.** Use `banner` and `list` instead. On Android, this value is still used to display the notification.
* - `banner`: the push notification is displayed as a banner. On Android, defaults to the same behavior as `alert`.
* - `list`: the push notification is displayed in the notification center. On Android, defaults to the same behavior as `alert`.
*
* An empty array can be provided if none of the options are desired.
*
* badge is only available for iOS.
*
* @since 1.0.0
* @example ["badge", "sound", "alert"]
* @example ["badge", "sound", "alert", "banner", "list"]
*/
presentationOptions: PresentationOption[];
};
Expand Down
Loading