Skip to content

Commit 200eb5e

Browse files
committed
Add removeLocalNotification API for Android
1 parent 2998877 commit 200eb5e

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

android/src/main/java/cn/jpush/reactnativejpush/JPushModule.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,25 @@ public void sendLocalNotification(ReadableMap map) {
515515
}
516516
}
517517

518+
@ReactMethod
519+
public void removeLocalNotification(int id) {
520+
try {
521+
Logger.d(TAG, "removeLocalNotification:"+id);
522+
JPushInterface.removeLocalNotification(getReactApplicationContext(), id);
523+
} catch (Exception e) {
524+
e.printStackTrace();
525+
}
526+
}
527+
@ReactMethod
528+
public void clearLocalNotifications() {
529+
try {
530+
Logger.d(TAG, "clearLocalNotifications");
531+
JPushInterface.clearLocalNotifications(getReactApplicationContext());
532+
} catch (Exception e) {
533+
e.printStackTrace();
534+
}
535+
}
536+
518537
@Override
519538
public void onHostResume() {
520539
Logger.d(TAG, "onHostResume");

documents/api.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
* [setTags](#settags)
1212
* [cleanTags](#cleantags)
1313
* [sendLocalNotification](#sendlocalnotification)
14+
* [clearLocalNotifications](#clearLocalNotifications)
15+
* [removeLocalNotification](#removeLocalNotification)
1416
* [clearAllNotifications](#clearallnotifications)
1517
* [clearNotificationById](#clearnotificationbyId)
1618
* [点击推送事件](#点击推送事件)
@@ -194,6 +196,23 @@ JPushModule.resumePush();
194196
})
195197
```
196198

199+
#### clearLocalNotifications
200+
201+
移除所有的本地通知
202+
203+
```
204+
JPushModule.clearLocalNotifications();
205+
```
206+
207+
#### removeLocalNotification
208+
209+
根据 notificationId 移除指定的本地通知, notificationId 为 int 类型。
210+
211+
```
212+
var notificationId = 5;
213+
JPushModule.removeLocalNotification(id);
214+
```
215+
197216
#### clearAllNotifications
198217

199218
清除所有通知

documents/api_en.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* [Receive Notification event](#receive-notification-event)
1414
* [Receive Custom Message Event](#receive-custom-message-event)
1515
* [sendLocalNotification](#sendlocalnotification)
16+
* [removeLocalNotification](#removeLocalNotification)
17+
* [clearLocalNotifications](#clearLocalNotifications)
1618
* [clearAllNotifications](#clearallnotifications)
1719
* [clearNotificationById](#clearnotificationbyId)
1820
* [iOS Only API](#ios-only-api)
@@ -149,6 +151,23 @@ reset tags.
149151
})
150152
```
151153

154+
#### clearLocalNotifications
155+
156+
Removes all local notifications
157+
158+
```
159+
JPushModule.clearLocalNotifications();
160+
```
161+
162+
#### removeLocalNotification
163+
164+
Remove the specified local notification by notificationId(int type)。
165+
166+
```
167+
var notificationId = 5;
168+
JPushModule.removeLocalNotification(id);
169+
```
170+
152171
#### clearAllNotifications
153172

154173
Clear all notifications.

0 commit comments

Comments
 (0)