How to use the react-native-notifications.NotificationsAndroid.setRegistrationTokenUpdateListener function in react-native-notifications

To help you get started, we’ve selected a few react-native-notifications examples, based on popular ways it is used in public projects.

github demokratie-live / democracy-client / src / hocs / PushNotifications.js View on Github external
}

          NotificationsIOS.addEventListener('notificationReceivedForeground', notification => {
            this.onNotificationReceivedForeground(notification.getData());
          });
          NotificationsIOS.addEventListener('notificationReceivedBackground', notification => {
            this.onNotificationReceivedBackground(notification.getData());
          });
          NotificationsIOS.addEventListener('notificationOpened', notification => {
            this.onNotificationOpened(notification.getData());
          });
          break;
        case 'android':
          if (!LISTENERS_ADDED) {
            LISTENERS_ADDED = true;
            NotificationsAndroid.setRegistrationTokenUpdateListener(async deviceToken => {
              // console.log('PUSHLOG: setRegistrationTokenUpdateListener', deviceToken);
              // TODO: Send the token to my server so it could send back push notifications...
              const tokenSucceeded = await client.mutate({
                mutation: ADD_TOKEN,
                variables: {
                  token: deviceToken,
                  os: 'android',
                },
              });
              if (tokenSucceeded) {
                await AsyncStorage.setItem('push-token', deviceToken);
              }
            });
            NotificationsAndroid.refreshToken();

            // On Android, we allow for only one (global) listener per each event type.
github RocketChat / Rocket.Chat.ReactNative / app / notifications / push / push.android.js View on Github external
constructor() {
		this.onRegister = null;
		this.onNotification = null;
		this.deviceToken = null;

		NotificationsAndroid.setRegistrationTokenUpdateListener((deviceToken) => {
			this.deviceToken = deviceToken;
		});

		NotificationsAndroid.setNotificationOpenedListener((notification) => {
			this.onNotification(notification);
		});
	}
github zulip / zulip-mobile / src / utils / notifications.android.js View on Github external
export const initializeNotifications = (auth: Auth, saveTokenPush: SavePushTokenCallback) => {
  NotificationsAndroid.setRegistrationTokenUpdateListener(async deviceToken => {
    try {
      const result = await registerPush(auth, deviceToken);
      saveTokenPush(deviceToken, result.msg, result.result);
    } catch (e) {
      logErrorRemotely(e, 'failed to register GCM');
    }
  });
};
github mattermost / mattermost-mobile / app / push_notifications / push_notifications.android.js View on Github external
constructor() {
        this.onRegister = null;
        this.onNotification = null;
        this.onReply = null;
        this.deviceNotification = null;
        this.deviceToken = null;

        NotificationsAndroid.setRegistrationTokenUpdateListener((deviceToken) => {
            this.deviceToken = deviceToken;
            if (this.onRegister) {
                this.onRegister({token: this.deviceToken});
            }
        });

        NotificationsAndroid.setNotificationReceivedListener((notification) => {
            if (notification) {
                const data = notification.getData();
                this.handleNotification(data, false);
            }
        });

        NotificationsAndroid.setNotificationOpenedListener((notification) => {
            if (notification) {
                const data = notification.getData();

react-native-notifications

Advanced Push Notifications (Silent, interactive notifications) for iOS & Android

MIT
Latest version published 5 months ago

Package Health Score

79 / 100
Full package analysis