Skip to content

Commit 45417ca

Browse files
committed
Merge pull request zetavg#26 from lukefanning/remove-all-listeners
Added remove all listeners function
2 parents 6839d8f + 1d4e714 commit 45417ca

File tree

2 files changed

+45
-30
lines changed

2 files changed

+45
-30
lines changed

README.md

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ dependencies {
116116
</manifest>
117117
```
118118

119-
> The `RECEIVE_BOOT_COMPLETED` permission is used to re-register all scheduled notifications after reboot.
119+
> The `RECEIVE_BOOT_COMPLETED` permission is used to re-register all scheduled notifications after reboot.
120120
> Requesting `VIBRATE` permission is required if you want to make the device vibrate while sending notifications.
121121
122122
- Edit `MainActivity.java` (usually at `android/app/src/main/java/com/<project-name>/MainActivity.java`) and add the annoated lines as below:
@@ -177,37 +177,37 @@ All available options on a notification are listed below:
177177

178178
#### Basic
179179

180-
**id (`number`)**
180+
**id (`number`)**
181181
The unique ID of this notification. It will be randomly chosen if not specified.
182182

183-
**subject (`string`)**
183+
**subject (`string`)**
184184
The notification subject. Defaults to the application name on Android.
185185

186-
**message (`string`)**
186+
**message (`string`)**
187187
The message showen in the notification.
188188

189-
**action (`string`)**
189+
**action (`string`)**
190190
An action name that can be used to determine what to do when this notification is clicked. Defaults to `DEFAULT`.
191191

192-
**payload (`object`)**
192+
**payload (`object`)**
193193
A custom payload object. It can be retrieved on events of this notification. Defaults to `{}`.
194194

195195

196196
#### Scheduling
197197

198-
**delay (`number`)**
198+
**delay (`number`)**
199199
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`.
200200

201-
**sendAt (`Date`)**
201+
**sendAt (`Date`)**
202202
Schedule this notification to show on a specified time. Note that it cannot be used with `delay`.
203203

204-
**repeatEvery (`string` or `number`)**
204+
**repeatEvery (`string` or `number`)**
205205
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.
206206

207-
**repeatCount (`number`)**
207+
**repeatCount (`number`)**
208208
Must use with `sendAt` and `repeatEvery`. End repeating this notification after n times. Note that it cannot be used with `endAt`.
209209

210-
**endAt (`Date`)**
210+
**endAt (`Date`)**
211211
Must use with `sendAt` and `repeatEvery`. End repeating this notification after a specified time. Note that it cannot be used with `repeatCount`.
212212

213213

@@ -243,61 +243,61 @@ Must use with `sendAt` and `repeatEvery`. End repeating this notification after
243243

244244
#### Customization
245245

246-
**priority (`number`)**
246+
**priority (`number`)**
247247
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`.
248248

249-
**smallIcon (`string`)**
249+
**smallIcon (`string`)**
250250
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`.
251251

252-
**largeIcon (`string`)**
252+
**largeIcon (`string`)**
253253
Not yet implemented.
254254

255-
**sound (`string`)**
255+
**sound (`string`)**
256256
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.
257257

258-
**vibrate (`string`)**
258+
**vibrate (`string`)**
259259
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.
260260

261-
**lights (`string`)**
261+
**lights (`string`)**
262262
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.
263263

264-
**autoClear (`boolean`)**
264+
**autoClear (`boolean`)**
265265
Clear this notification automatically after the user clicks on it. Defaults to `true`.
266266

267-
**onlyAlertOnce (`boolean`)**
267+
**onlyAlertOnce (`boolean`)**
268268
Do not let the sound, vibrate and ticker to be played if the notification is already showing.
269269

270-
**tickerText (`string`)**
270+
**tickerText (`string`)**
271271
Set the text to show on ticker. Defaults to `<subject>: <message>`. Set this to `null` to disable ticker.
272272

273-
**when (`Date`)**
273+
**when (`Date`)**
274274
Add a timestamp pertaining to the notification (usually the time the event occurred).
275275

276-
**bigText (`string`)**
276+
**bigText (`string`)**
277277
Set the text to be shown when the user expand the notification.
278278

279-
**subText (`string`)**
279+
**subText (`string`)**
280280
Set the third line of text in the platform notification template. Note that it cannot be used with `progress`.
281281

282-
**progress (`number`)**
282+
**progress (`number`)**
283283
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`.
284284

285-
**color (`string`)**
285+
**color (`string`)**
286286
Color to be applied by the standard Style templates when presenting this notification.
287287

288-
**number (`number`)**
288+
**number (`number`)**
289289
Set a number on the notification.
290290

291-
**private (`boolean`)**
291+
**private (`boolean`)**
292292
Not yet implemented.
293293

294-
**ongoing (`boolean`)**
294+
**ongoing (`boolean`)**
295295
Not yet implemented.
296296

297-
**category (`string`)**
297+
**category (`string`)**
298298
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.
299299

300-
**localOnly (`boolean`)**
300+
**localOnly (`boolean`)**
301301
Set whether or not this notification should not bridge to other devices.
302302

303303
### Handle Notification Click Event
@@ -330,6 +330,12 @@ Notification.addListener('press', function(e) {
330330
});
331331
```
332332

333+
Once you no longer need to listen to `sysNotificationClick` events de-register the listener functions with:
334+
335+
```js
336+
Notification.removeAllListeners('press');
337+
```
338+
333339
### Manage Scheduled Notifications
334340

335341
Sometimes you'll need to get the scheduled notifications (which has `delay` or `sendAt` set up) that you had created before. You can use `Notification.getIDs()` to retrieve an array of IDs of available (i.e. will be send in the future) scheduled notifications.

index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ var Notification = {
8989
}
9090
},
9191

92+
removeAllListeners: function (type) {
93+
switch (type) {
94+
case 'press':
95+
case 'click':
96+
DeviceEventEmitter.removeAllListeners('sysNotificationClick');
97+
break;
98+
}
99+
},
100+
92101
module: NotificationModule
93102
}
94103

0 commit comments

Comments
 (0)