Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
635 views
in Technique[技术] by (71.8m points)

android - addNotificationReceivedListener not receiving notification in expo react native while using expo-notifications

I am using expo react native on a project and I am using the expo-notifications package within the project.

I have added "useNextNotificationsApi": true, to my app.json file under the android object which is under the expo object so expo.android.useNextNotificationsApi : true.

I also have the experienceId set on the message I am sending to expo's server from my server, I am using the https://github.com/expo/expo-server-sdk-node package to do the sending.

   messages.push({
               to: red_user.fcm_token,
               sound: 'default',
               title: "Stylist Response",
               body: "Stylist has agreed to fulfill the request",
               data: {
                   experienceId: "@glamcentralng/GlamCentral",
                   order: order._id,
                   stylist_response: "agreed" 
               },
          })  

In my expo react native app I am using the expo-notifications package as I mentioned and I have the following setup in my class component.

import * as Notifications from 'expo-notifications';

.
.
.
.

 componentDidMount() {

    //Not working at all 
    Notifications.addNotificationReceivedListener( notification => {
      console.log(notification);
      this._handleNotification(notification)
    });

    //Working well
    Notifications.addNotificationResponseReceivedListener(response => {
      console.log(response);
    });
  
    this.registerForPushNotificationsAsyncNew();
}

The addNotificationReceivedListener does not receive the notification when it comes in, but I see it as a normal notification on my real Android device (I am NOT using an emulator). AS per the documentation when i click on the notification the addNotificationResponseReceivedListener should handle it and it does. So addNotificationReceivedListener does NOT work but addNotificationResponseReceivedListener works well.

One more thing to add is that I am getting a token in the function that does the registration as per the documentation.

Not sure how to fix this as I have checked other threads on here and github. Any help is appreciated.

question from:https://stackoverflow.com/questions/65832863/addnotificationreceivedlistener-not-receiving-notification-in-expo-react-native

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...