Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DailyNotificationTrigger in expo-notifications not working on Android device

I am trying to implement notifications in an Expo app using expo-notifications. My trigger object in scheduleNotificationAsync conforms to the DailyNotificationTrigger interface, still I'm getting this error:

[Unhandled promise rejection: Error: Failed to schedule the notification. Trigger of type: calendar is not supported on Android.]

This is the snippet of code that produces the error:

Notifications.scheduleNotificationAsync({
  content: {
    title: 'Complete a quiz',
    body: "👋 Don't forget solve a quiz today!",
  },
  trigger: {
    type: 'daily',
    hour: 8,
    minute: 0,
  },
})

My target device is an emulator running on Android 10. Please help me identify and fix the problem.

like image 585
Kewal Shah Avatar asked Jun 28 '20 11:06

Kewal Shah


People also ask

Does Expo support Push Notifications?

Along with the expo-notifications module, which provides all the client-side functionality for push notifications, Expo can also handle sending these notifications off to APNs and FCM for you! All you need to do is send the request to our servers with the ExpoPushToken you grabbed in the last step.

How do you test expo notifications?

To use it, go to Expo's push notifications tool, add the Expo push token from your app, fulfil the message fields and send the notification.

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.


Video Answer


2 Answers

Got my hint from interface DailyTriggerInput. Working code should be like following:

Notifications.scheduleNotificationAsync({
    content: { 
        title: 'Winter is coming!' 
    }, 
    trigger: { 
        hour: 18, minute: 36, repeats: true 
    }
})
like image 159
Hunnain Avatar answered Oct 21 '22 15:10

Hunnain


It's not about Daily trigger. Mistake is in a Expo Documentation. It says nothing about Android which not supports calendar. It taken 3 days to me to solve this issue.

So for the next generations, don't use days, hours and minutes in trigger (on Android platform). Just seconds work properly.

like image 1
Joey Drab Avatar answered Oct 21 '22 15:10

Joey Drab