Skip to content

Commit

Permalink
Allow numbers for number and id in Android.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dallas62 committed May 8, 2020
1 parent f2dd349 commit 7347b8e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Features

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

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

### Fixed

- (Android) `number` and `id` are now correctly handled as number in Android.

## [3.3.1] - 2020-05-01

### Fixed
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ EXAMPLE:
```javascript
PushNotification.localNotification({
/* Android Only Properties */
id: "0", // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
id: 0, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
ticker: "My Notification Ticker", // (optional)
autoCancel: true, // (optional) default: true
largeIcon: "ic_launcher", // (optional) default: "ic_launcher"
Expand Down Expand Up @@ -531,6 +531,8 @@ Same parameters as `PushNotification.localNotification()`

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

`PushNotification.unsubscribeFromTopic(topic: string)` Unsubscribe from a topic (works only with Firebase)

## Checking Notification Permissions

`PushNotification.checkPermissions(callback: Function)` Check permissions
Expand Down
12 changes: 10 additions & 2 deletions example/NotifService.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@ export default class NotifService {

NotificationHandler.onRegister(onRegister);
NotificationHandler.attachNotification(onNotification);

// Clear badge number at start
PushNotification.getApplicationIconBadgeNumber(function(number) {
if(number > 0) {
PushNotification.setApplicationIconBadgeNumber(0);
}
});
}

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

/* Android Only Properties */
id: '' + this.lastId, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
id: this.lastId, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
ticker: 'My Notification Ticker', // (optional)
autoCancel: true, // (optional) default: true
largeIcon: 'ic_launcher', // (optional) default: "ic_launcher"
Expand All @@ -71,6 +78,7 @@ export default class NotifService {
title: 'Scheduled Notification', // (optional)
message: 'My Notification Message', // (required)
playSound: !!soundName, // (optional) default: true
number: 10, // (optional) Valid 32 bit integer specified as string. default: none (Cannot be zero)
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)
});
}
Expand Down
16 changes: 16 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ Notifications.localNotification = function(details) {
userInfo: details.userInfo
});
} else {
if(details && typeof details.id === 'number') {
details.id = '' + details.id;
}

if(details && typeof details.number === 'number') {
details.number = '' + details.number;
}

this.handler.presentLocalNotification(details);
}
};
Expand Down Expand Up @@ -178,6 +186,14 @@ Notifications.localNotificationSchedule = function(details) {
}
this.handler.scheduleLocalNotification(iosDetails);
} else {
if(details && typeof details.id === 'number') {
details.id = '' + details.id;
}

if(details && typeof details.number === 'number') {
details.number = '' + details.number;
}

details.fireDate = details.date.getTime();
delete details.date;
// ignore iOS only repeatType
Expand Down

0 comments on commit 7347b8e

Please sign in to comment.