Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expo notifications not working when channel id is used

I am using the following code to create two channels for my expo react app, on Android:

Notifications.setNotificationChannelAsync("default", {
            name: "default",
            importance: Notifications.AndroidImportance.MAX,
            vibrationPattern: [0, 250, 250, 250],
            lightColor: "#FF231F7C",
        })  

Notifications.setNotificationChannelAsync("gameupdates", {
                name: "gameupdates",
                importance: Notifications.AndroidImportance.MAX,
                vibrationPattern: [0, 250, 250, 250],
                lightColor: "#FF231F7C",
            })

The channel is successfully created and I can even find it when I go into the Expo app notification options.

When I send a notification using expo's tool without any channel id, it works fine. However, when I use the channel id "gameupdates", the notification never reaches my phone.

Any idea why?

I am on the expo sdk 38.

like image 687
Ryan Pergent Avatar asked Aug 10 '20 10:08

Ryan Pergent


People also ask

How do I customize my Expo notifications?

To configure expo-notifications , use the built-in config plugin in the app. json or app. config. js for EAS Build or with npx expo run:[android|ios] .

How do I add notifications to my channel?

To turn on the setting for a development device running Android 8.0 (API level 26), navigate to Settings > Developer options and enable Show notification channel warnings.

Do expo push tokens expire?

The ExpoPushToken will never "expire" but if one of your users uninstalls the app, you'll receive a DeviceNotRegistered error back from Expo's servers, meaning you should stop sending notifications to this app.


2 Answers

Fixed it! The issues was that I needed to add android.useNextNotificationsApi: true to the app.json. Then I had to do expo:build and manually upload the build.

like image 84
Ryan Pergent Avatar answered Sep 28 '22 10:09

Ryan Pergent


You have created your channel successfully but doesn't updated your app's expo notifications settings. For this you must add -

android: {
...
"useNextNotificationsApi": true
}

in your app.json file.

Then just run your code by clearing expo cache like -

expo start -c

And test it! You will start receiving the notifications on your Android 10+ mobiles also.

like image 29
AMOL PATIL Avatar answered Sep 28 '22 08:09

AMOL PATIL