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

Commit 7347b8e

Browse files
committed
Allow numbers for number and id in Android.
1 parent f2dd349 commit 7347b8e

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99

1010
### Features
1111

12+
- (Android) Call `onRegister` when [Firebase renew token](<https://firebase.google.com/docs/reference/android/com/google/firebase/messaging/FirebaseMessagingService#onNewToken(java.lang.String)>).
1213
- (Android) Add a new key in `AndroidManifest.xml` to allow/remove notification in foreground.
1314

1415
```xml
@@ -18,6 +19,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1819

1920
### Fixed
2021

22+
- (Android) `number` and `id` are now correctly handled as number in Android.
23+
2124
## [3.3.1] - 2020-05-01
2225

2326
### Fixed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ EXAMPLE:
273273
```javascript
274274
PushNotification.localNotification({
275275
/* Android Only Properties */
276-
id: "0", // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
276+
id: 0, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
277277
ticker: "My Notification Ticker", // (optional)
278278
autoCancel: true, // (optional) default: true
279279
largeIcon: "ic_launcher", // (optional) default: "ic_launcher"
@@ -531,6 +531,8 @@ Same parameters as `PushNotification.localNotification()`
531531

532532
`PushNotification.subscribeToTopic(topic: string)` Subscribe to a topic (works only with Firebase)
533533

534+
`PushNotification.unsubscribeFromTopic(topic: string)` Unsubscribe from a topic (works only with Firebase)
535+
534536
## Checking Notification Permissions
535537

536538
`PushNotification.checkPermissions(callback: Function)` Check permissions

example/NotifService.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,20 @@ export default class NotifService {
77

88
NotificationHandler.onRegister(onRegister);
99
NotificationHandler.attachNotification(onNotification);
10+
11+
// Clear badge number at start
12+
PushNotification.getApplicationIconBadgeNumber(function(number) {
13+
if(number > 0) {
14+
PushNotification.setApplicationIconBadgeNumber(0);
15+
}
16+
});
1017
}
1118

1219
localNotif(soundName) {
1320
this.lastId++;
1421
PushNotification.localNotification({
1522
/* Android Only Properties */
16-
id: '' + this.lastId, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
23+
id: this.lastId, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
1724
ticker: 'My Notification Ticker', // (optional)
1825
autoCancel: true, // (optional) default: true
1926
largeIcon: 'ic_launcher', // (optional) default: "ic_launcher"
@@ -48,7 +55,7 @@ export default class NotifService {
4855
date: new Date(Date.now() + 30 * 1000), // in 30 secs
4956

5057
/* Android Only Properties */
51-
id: '' + this.lastId, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
58+
id: this.lastId, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
5259
ticker: 'My Notification Ticker', // (optional)
5360
autoCancel: true, // (optional) default: true
5461
largeIcon: 'ic_launcher', // (optional) default: "ic_launcher"
@@ -71,6 +78,7 @@ export default class NotifService {
7178
title: 'Scheduled Notification', // (optional)
7279
message: 'My Notification Message', // (required)
7380
playSound: !!soundName, // (optional) default: true
81+
number: 10, // (optional) Valid 32 bit integer specified as string. default: none (Cannot be zero)
7482
soundName: soundName ? soundName : 'default', // (optional) Sound to play when the notification is shown. Value of 'default' plays the default sound. It can be set to a custom sound such as 'android.resource://com.xyz/raw/my_sound'. It will look for the 'my_sound' audio file in 'res/raw' directory and play it. default: 'default' (default sound is played)
7583
});
7684
}

index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ Notifications.localNotification = function(details) {
140140
userInfo: details.userInfo
141141
});
142142
} else {
143+
if(details && typeof details.id === 'number') {
144+
details.id = '' + details.id;
145+
}
146+
147+
if(details && typeof details.number === 'number') {
148+
details.number = '' + details.number;
149+
}
150+
143151
this.handler.presentLocalNotification(details);
144152
}
145153
};
@@ -178,6 +186,14 @@ Notifications.localNotificationSchedule = function(details) {
178186
}
179187
this.handler.scheduleLocalNotification(iosDetails);
180188
} else {
189+
if(details && typeof details.id === 'number') {
190+
details.id = '' + details.id;
191+
}
192+
193+
if(details && typeof details.number === 'number') {
194+
details.number = '' + details.number;
195+
}
196+
181197
details.fireDate = details.date.getTime();
182198
delete details.date;
183199
// ignore iOS only repeatType

0 commit comments

Comments
 (0)