mirror of
https://github.com/zhigang1992/react-native-notifications.git
synced 2026-06-11 08:13:28 +08:00
Handling notification post (local notif style)
This commit is contained in:
@@ -18,5 +18,11 @@ public interface IPushNotification {
|
||||
*/
|
||||
void onOpened();
|
||||
|
||||
/**
|
||||
* Handle a request to post this notification.
|
||||
* @return ID to optionally use for notification deletion.
|
||||
*/
|
||||
int onPostRequest();
|
||||
|
||||
PushNotificationProps asProps();
|
||||
}
|
||||
|
||||
@@ -68,15 +68,20 @@ public class PushNotification implements IPushNotification {
|
||||
PushNotificationsDrawer.get(mContext).onNotificationOpened();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onPostRequest() {
|
||||
return postNotification();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PushNotificationProps asProps() {
|
||||
return mNotificationProps.copy();
|
||||
}
|
||||
|
||||
protected void postNotification() {
|
||||
protected int postNotification() {
|
||||
final PendingIntent pendingIntent = getCTAPendingIntent();
|
||||
final Notification notification = buildNotification(pendingIntent);
|
||||
postNotification((int) System.currentTimeMillis(), notification);
|
||||
return postNotification(notification);
|
||||
}
|
||||
|
||||
protected void digestNotification() {
|
||||
@@ -141,11 +146,21 @@ public class PushNotification implements IPushNotification {
|
||||
.setAutoCancel(true);
|
||||
}
|
||||
|
||||
protected int postNotification(Notification notification) {
|
||||
int id = createNotificationId(notification);
|
||||
postNotification(id, notification);
|
||||
return id;
|
||||
}
|
||||
|
||||
protected void postNotification(int id, Notification notification) {
|
||||
final NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
notificationManager.notify(id, notification);
|
||||
}
|
||||
|
||||
protected int createNotificationId(Notification notification) {
|
||||
return (int) System.currentTimeMillis();
|
||||
}
|
||||
|
||||
protected ReactContext getRunningReactContext() {
|
||||
final ReactNativeHost rnHost = ((ReactApplication) mContext.getApplicationContext()).getReactNativeHost();
|
||||
if (!rnHost.hasInstance()) {
|
||||
|
||||
Reference in New Issue
Block a user