From 122053f22838bd40f8f19fd039d22d82bcaabbcd Mon Sep 17 00:00:00 2001 From: Richard de Wit Date: Fri, 22 Jan 2016 15:45:30 +0100 Subject: [PATCH 1/6] Add TOC and reformat Creating Notifications topic You were putting the contents of Creating Notifications in definition lists, this escaped the backticks making the explanations hard to read. E.g. `tickerText` was showing really strange saying: > Defaults to `: `. instead of > Defaults to `: `. because the "HTML" wasn't escaped by the backticks. --- README.md | 140 +++++++++++++++++++++++++++++------------------------- 1 file changed, 75 insertions(+), 65 deletions(-) diff --git a/README.md b/README.md index ea189e2..8770506 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,20 @@ Send or schedule Android system notifications for React Native. +## Table of Contents + + * [Installation](#installation) + * [Usage](#usage) + * [Creating Notifications](#creating-notifications) + * [Basic](#basic) + * [Scheduling](#scheduling) + * [Customization](#customization) + * [Handle Notification Click Event](#handle-notification-click-event) + * [Manage Scheduled Notifications](#manage-scheduled-notifications) + * [Clearing Notifications](#clearing-notifications) + * [Push Notifications On Android](#push-notifications-on-android) + +--- ```js import React, { DeviceEventEmitter } from 'react-native'; @@ -164,43 +178,41 @@ Notification.create({ All available options on a notification are listed below: -**Basic** +#### Basic + +**id (`number`)** +The unique ID of this notification. It will be randomly chosen if not specified. + +**subject (`string`)** +The notification subject. Defaults to the application name on Android. -
-
id (`number`)
-
The unique ID of this notification. It will be randomly chosen if not specified.
+**message (`string`)** +The message showen in the notification. -
subject (`string`)
-
The notification subject. Defaults to the application name on Android.
+**action (`string`)** +An action name that can be used to determine what to do when this notification is clicked. Defaults to `DEFAULT`. -
message (`string`)
-
The message showen in the notification.
+**payload (`object`)** +A custom payload object. It can be retrieved on events of this notification. Defaults to `{}`. -
action (`string`)
-
An action name that can be used to determine what to do when this notification is clicked. Defaults to `DEFAULT`.
-
payload (`object`)
-
A custom payload object. It can be retrieved on events of this notification. Defaults to `{}`.
-
+#### Scheduling -**Scheduling** +**delay (`number`)** +Milliseconds to delay before showing this notification after it is created. Useful when creating countdown alarms, reminders, etc. Note that it cannot be used with `sendAt`. -
-
delay (`number`)
-
Milliseconds to delay before showing this notification after it is created. Useful when creating countdown alarms, reminders, etc. Note that it cannot be used with `sendAt`.
+**sendAt (`Date`)** +Schedule this notification to show on a specified time. Note that it cannot be used with `delay`. -
sendAt (`Date`)
-
Schedule this notification to show on a specified time. Note that it cannot be used with `delay`.
+**repeatEvery (`string` or `number`)** +Must use with `sendAt`. Schedule this notification to repeat. Can be `minute`, `hour`, `halfDay`, `day`, `week`, `month`, `year` or a number of time in milliseconds. -
repeatEvery (`string` or `number`)
-
Must use with `sendAt`. Schedule this notification to repeat. Can be `minute`, `hour`, `halfDay`, `day`, `week`, `month`, `year` or a number of time in milliseconds.
+**repeatCount (`number`)** +Must use with `sendAt` and `repeatEvery`. End repeating this notification after n times. Note that it cannot be used with `endAt`. -
repeatCount (`number`)
-
Must use with `sendAt` and `repeatEvery`. End repeating this notification after n times. Note that it cannot be used with `endAt`.
+**endAt (`Date`)** +Must use with `sendAt` and `repeatEvery`. End repeating this notification after a specified time. Note that it cannot be used with `repeatCount`. -
endAt (`Date`)
-
Must use with `sendAt` and `repeatEvery`. End repeating this notification after a specified time. Note that it cannot be used with `repeatCount`.
-
> Some Samples of Scheduled Notifications > @@ -232,63 +244,61 @@ All available options on a notification are listed below: > }); > ``` -**Customization** +#### Customization -
-
priority (`number`)
-
Priority of this notification, can be `-2`, `-1`, `0`, `1`, `2`. When this is set to `1` or `2`, heads-up notification will be more likely to show on Android 5+. Defaults to `1`.
+**priority (`number`)** +Priority of this notification, can be `-2`, `-1`, `0`, `1`, `2`. When this is set to `1` or `2`, heads-up notification will be more likely to show on Android 5+. Defaults to `1`. -
smallIcon (`string`)
-
The icon (file name) to show. This icon must be placed in the project's `android/app/src/main/res/mipmap-*` folder. Defaults to `ic_launcher`.
+**smallIcon (`string`)** +The icon (file name) to show. This icon must be placed in the project's `android/app/src/main/res/mipmap-*` folder. Defaults to `ic_launcher`. -
largeIcon (`string`)
-
Not yet implemented.
+**largeIcon (`string`)** +Not yet implemented. -
sound (`string`)
-
Set the sound to play. Defaults to `default` as using the default notification sound, or set this to `null` to disable the sound. Other options are not yet implemented.
+**sound (`string`)** +Set the sound to play. Defaults to `default` as using the default notification sound, or set this to `null` to disable the sound. Other options are not yet implemented. -
vibrate (`string`)
-
Set the vibration pattern to use. Defaults to `default` as using the default notification vibrate, or set this to `null` to disable the vibrate. Other options are not yet implemented.
+**vibrate (`string`)** +Set the vibration pattern to use. Defaults to `default` as using the default notification vibrate, or set this to `null` to disable the vibrate. Other options are not yet implemented. -
lights (`string`)
-
Set the desired color for the indicator LED on the device. Defaults to `default` as using the default notification lights, or set this to `null` to disable the lights. Other options are not yet implemented.
+**lights (`string`)** +Set the desired color for the indicator LED on the device. Defaults to `default` as using the default notification lights, or set this to `null` to disable the lights. Other options are not yet implemented. -
autoClear (`boolean`)
-
Clear this notification automatically after the user clicks on it. Defaults to `true`.
+**autoClear (`boolean`)** +Clear this notification automatically after the user clicks on it. Defaults to `true`. -
onlyAlertOnce (`boolean`)
-
Do not let the sound, vibrate and ticker to be played if the notification is already showing.
+**onlyAlertOnce (`boolean`)** +Do not let the sound, vibrate and ticker to be played if the notification is already showing. -
tickerText (`string`)
-
Set the text to show on ticker. Defaults to `: `. Set this to `null` to disable ticker.
+**tickerText (`string`)** +Set the text to show on ticker. Defaults to `: `. Set this to `null` to disable ticker. -
when (`Date`)
-
Add a timestamp pertaining to the notification (usually the time the event occurred).
+**when (`Date`)** +Add a timestamp pertaining to the notification (usually the time the event occurred). -
subText (`string`)
-
Set the third line of text in the platform notification template. Note that it cannot be used with `progress`.
+**subText (`string`)** +Set the third line of text in the platform notification template. Note that it cannot be used with `progress`. -
progress (`number`)
-
Set the progress this notification represents, range: `0.0` ~ `1.0`. Set this to a number lower then zero to get an indeterminate progress. Note that it cannot be used with `subText`.
+**progress (`number`)** +Set the progress this notification represents, range: `0.0` ~ `1.0`. Set this to a number lower then zero to get an indeterminate progress. Note that it cannot be used with `subText`. -
color (`string`)
-
Not yet implemented. Color to be applied by the standard Style templates when presenting this notification.
+**color (`string`)** +Not yet implemented. Color to be applied by the standard Style templates when presenting this notification. -
number (`number`)
-
Set a number on the notification.
+**number (`number`)** +Set a number on the notification. -
private (`boolean`)
-
Not yet implemented.
+**private (`boolean`)** +Not yet implemented. -
ongoing (`boolean`)
-
Not yet implemented.
+**ongoing (`boolean`)** +Not yet implemented. -
category (`string`)
-
Set the notification category, e.g.: `alarm`, `call`, `email`, `event`, `progress`, `reminder`, `social`. It may be used by the Android system for ranking and filtering.
+**category (`string`)** +Set the notification category, e.g.: `alarm`, `call`, `email`, `event`, `progress`, `reminder`, `social`. It may be used by the Android system for ranking and filtering. -
localOnly (`boolean`)
-
Set whether or not this notification should not bridge to other devices.
-
+**localOnly (`boolean`)** +Set whether or not this notification should not bridge to other devices. ### Handle Notification Click Event From 94773d1a83bcc48a1ed4a46f755567477d53d91a Mon Sep 17 00:00:00 2001 From: kf <7kfpun@gmail.com> Date: Mon, 1 Feb 2016 15:08:45 +0800 Subject: [PATCH 2/6] Update peerDependencies react-native-gcm-android --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f4c600f..429d1cd 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,6 @@ ], "peerDependencies": { "react-native": ">=0.15.0", - "react-native-gcm-android": "^0.1.8" + "react-native-gcm-android": "^0.2.0" } } From 2225c5d660a3931b975430a380c0ebadd51ec8f7 Mon Sep 17 00:00:00 2001 From: Juliano Castilho Date: Thu, 4 Feb 2016 22:01:08 -0300 Subject: [PATCH 3/6] Adding bigText support (expanded notification) --- README.md | 3 +++ .../io/neson/react-native/notification/Notification.java | 6 ++++++ .../react-native/notification/NotificationAttributes.java | 3 +++ 3 files changed, 12 insertions(+) diff --git a/README.md b/README.md index 8770506..c6a3340 100644 --- a/README.md +++ b/README.md @@ -276,6 +276,9 @@ Set the text to show on ticker. Defaults to `: `. Set this to **when (`Date`)** Add a timestamp pertaining to the notification (usually the time the event occurred). +**bigText (`string`)** +Set the text to be shown when the user expand the notification. + **subText (`string`)** Set the third line of text in the platform notification template. Note that it cannot be used with `progress`. diff --git a/android/src/main/java/io/neson/react-native/notification/Notification.java b/android/src/main/java/io/neson/react-native/notification/Notification.java index eb4a382..a1d3f53 100644 --- a/android/src/main/java/io/neson/react-native/notification/Notification.java +++ b/android/src/main/java/io/neson/react-native/notification/Notification.java @@ -123,6 +123,12 @@ public android.app.Notification build() { notificationBuilder.setPriority(attributes.priority); } + if (attributes.bigText != null) { + notificationBuilder + .setStyle(new android.app.Notification.BigTextStyle() + .bigText(attributes.bigText)); + } + int defaults = 0; if ("default".equals(attributes.sound)) { diff --git a/android/src/main/java/io/neson/react-native/notification/NotificationAttributes.java b/android/src/main/java/io/neson/react-native/notification/NotificationAttributes.java index 90f95c5..4bfff8e 100644 --- a/android/src/main/java/io/neson/react-native/notification/NotificationAttributes.java +++ b/android/src/main/java/io/neson/react-native/notification/NotificationAttributes.java @@ -41,6 +41,7 @@ public class NotificationAttributes { public Boolean onlyAlertOnce; public String tickerText; public Long when; + public String bigText; public String subText; public Integer progress; public String color; @@ -117,6 +118,7 @@ public void loadFromReadableMap(ReadableMap readableMap) { if (readableMap.hasKey("onlyAlertOnce")) onlyAlertOnce = readableMap.getBoolean("onlyAlertOnce"); if (readableMap.hasKey("tickerText")) tickerText = readableMap.getString("tickerText"); if (readableMap.hasKey("when")) when = Long.parseLong(readableMap.getString("when")); + if (readableMap.hasKey("bigText")) bigText = readableMap.getString("bigText"); if (readableMap.hasKey("subText")) subText = readableMap.getString("subText"); if (readableMap.hasKey("progress")) progress = readableMap.getInt("progress"); if (readableMap.hasKey("color")) color = readableMap.getString("color"); @@ -162,6 +164,7 @@ public ReadableMap asReadableMap() { if (onlyAlertOnce != null) writableMap.putBoolean("onlyAlertOnce", onlyAlertOnce); if (tickerText != null) writableMap.putString("tickerText", tickerText); if (when != null) writableMap.putString("when", Long.toString(when)); + if (bigText != null) writableMap.putString("bigText", bigText); if (subText != null) writableMap.putString("subText", subText); if (progress != null) writableMap.putInt("progress", progress); if (color != null) writableMap.putString("color", color); From 1da7ca29294e2dc3af05d18df67b1aff2ac95176 Mon Sep 17 00:00:00 2001 From: Juliano Castilho Date: Fri, 5 Feb 2016 01:54:57 -0300 Subject: [PATCH 4/6] Improving sysModuleNotificationClick event --- .../NotificationEventReceiver.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/android/src/main/java/io/neson/react-native/notification/NotificationEventReceiver.java b/android/src/main/java/io/neson/react-native/notification/NotificationEventReceiver.java index 38de120..226b6fc 100644 --- a/android/src/main/java/io/neson/react-native/notification/NotificationEventReceiver.java +++ b/android/src/main/java/io/neson/react-native/notification/NotificationEventReceiver.java @@ -30,7 +30,7 @@ public void onReceive(Context context, Intent intent) { Log.i("ReactSystemNotification", "NotificationEventReceiver: Recived: " + extras.getString(ACTION) + ", Notification ID: " + extras.getInt(NOTIFICATION_ID) + ", payload: " + extras.getString(PAYLOAD)); - // If the application is not running, start it with the notification + // If the application is not running or is not in foreground, start it with the notification // passed in if (!applicationIsRunning(context)) { String packageName = context.getApplicationContext().getPackageName(); @@ -41,20 +41,25 @@ public void onReceive(Context context, Intent intent) { launchIntent.putExtra("initialSysNotificationPayload", extras.getString(PAYLOAD)); context.startActivity(launchIntent); - Log.i("ReactSystemNotification", "NotificationEventReceiver: Launching: " + packageName); - // If the application is running, send a brodcast + sendBroadcast(context, extras); // Send a broadcast after come from background to foreground } else { - Intent brodcastIntent = new Intent("NotificationEvent"); - brodcastIntent.putExtra("id", extras.getInt(NOTIFICATION_ID)); - brodcastIntent.putExtra("action", extras.getString(ACTION)); - brodcastIntent.putExtra("payload", extras.getString(PAYLOAD)); - context.sendBroadcast(brodcastIntent); - Log.v("ReactSystemNotification", "NotificationEventReceiver: Broadcast Sent: NotificationEvent: " + extras.getString(ACTION) + ", Notification ID: " + extras.getInt(NOTIFICATION_ID) + ", payload: " + extras.getString(PAYLOAD)); + sendBroadcast(context, extras); // If the application is already running in foreground, send a brodcast too } } + private void sendBroadcast(Context context, Bundle extras) { + Intent brodcastIntent = new Intent("NotificationEvent"); + + brodcastIntent.putExtra("id", extras.getInt(NOTIFICATION_ID)); + brodcastIntent.putExtra("action", extras.getString(ACTION)); + brodcastIntent.putExtra("payload", extras.getString(PAYLOAD)); + + context.sendBroadcast(brodcastIntent); + Log.v("ReactSystemNotification", "NotificationEventReceiver: Broadcast Sent: NotificationEvent: " + extras.getString(ACTION) + ", Notification ID: " + extras.getInt(NOTIFICATION_ID) + ", payload: " + extras.getString(PAYLOAD)); + } + private boolean applicationIsRunning(Context context) { ActivityManager activityManager = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE); From b7f41c005a9fa7b2d076995b42d2385d63c93f67 Mon Sep 17 00:00:00 2001 From: Juliano Castilho Date: Sun, 7 Feb 2016 00:12:30 -0300 Subject: [PATCH 5/6] Adding color support --- .../react-native/notification/Notification.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/android/src/main/java/io/neson/react-native/notification/Notification.java b/android/src/main/java/io/neson/react-native/notification/Notification.java index a1d3f53..eae0d23 100644 --- a/android/src/main/java/io/neson/react-native/notification/Notification.java +++ b/android/src/main/java/io/neson/react-native/notification/Notification.java @@ -21,6 +21,7 @@ import io.neson.react.notification.NotificationPublisher; import android.util.Log; +import android.graphics.Color; /** * An object-oriented Wrapper class around the system notification class. @@ -123,12 +124,6 @@ public android.app.Notification build() { notificationBuilder.setPriority(attributes.priority); } - if (attributes.bigText != null) { - notificationBuilder - .setStyle(new android.app.Notification.BigTextStyle() - .bigText(attributes.bigText)); - } - int defaults = 0; if ("default".equals(attributes.sound)) { @@ -158,6 +153,16 @@ public android.app.Notification build() { notificationBuilder.setShowWhen(true); } + if (attributes.bigText != null) { + notificationBuilder + .setStyle(new android.app.Notification.BigTextStyle() + .bigText(attributes.bigText)); + } + + if (attributes.color != null) { + notificationBuilder.setColor(Color.parseColor(attributes.color)); + } + if (attributes.subText != null) { notificationBuilder.setSubText(attributes.subText); } From 3231101d18ebf1bd7b4df99dc7886466492210f9 Mon Sep 17 00:00:00 2001 From: Juliano Castilho Date: Sun, 7 Feb 2016 00:13:21 -0300 Subject: [PATCH 6/6] Updating README about color --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c6a3340..ec11ebd 100644 --- a/README.md +++ b/README.md @@ -286,7 +286,7 @@ Set the third line of text in the platform notification template. Note that it c Set the progress this notification represents, range: `0.0` ~ `1.0`. Set this to a number lower then zero to get an indeterminate progress. Note that it cannot be used with `subText`. **color (`string`)** -Not yet implemented. Color to be applied by the standard Style templates when presenting this notification. +Color to be applied by the standard Style templates when presenting this notification. **number (`number`)** Set a number on the notification.