Local notification problems when testing on android

I am trying to display a simple notification after a set amount of time which will later open the app and show a form to give feedback but am having a number of problems.

With the current code below I receive warnings in ADB as follows:

06-27 12:56:21.387 19257 19277 I Corona  : WARNING: notifications.scheduleNotification(time [, options]), Invalid option ‘badge’

06-27 12:56:21.387 19257 19277 I Corona  : WARNING: notifications.scheduleNotification(time [, options]), Invalid option ‘alert’

06-27 12:56:21.387 19257 19277 I Corona  : WARNING: notifications.scheduleNotification(time [, options]), Invalid option ‘custom’

The notification then does not appear after the set time.  When I then close the app (by swiping it away in the app list) and open it again, the notification appears instantly as the app starts.  On top of this, when I tap the notification the app does not open.  If I schedule multiple notifications they all appear when restarting the app and if they are stacked in the android notification bar the app does open when the stack is tapped.

main.lua (simplified):

notifications = require( "plugin.notifications.v2" ) composer = require( "composer" ) local launchArgs = ... -- Listen for notifications function onNotification( event )     print( event.name )     if ( event.custom ) then         print( event.custom.foo )     end     if ( event.type == "local" ) then         -- Handle the local notification         local badgeNum = native.getProperty( "applicationIconBadgeNumber" )         if ( badgeNum \> 0 ) then             badgeNum = badgeNum - 1             native.setProperty( "applicationIconBadgeNumber", badgeNum )         end     elseif ( event.type == "remote" ) then         -- Handle the push notification         if ( event.badge and event.badge \> 0 ) then             native.setProperty( "applicationIconBadgeNumber", event.badge - 1 )         end     end end Runtime:addEventListener( "notification", onNotification )       if ( launchArgs and launchArgs.notification ) then     onNotification( launchArgs.notification ) end composer.gotoScene("core.loading")

homeTab.lua (simplified):

local composer = require( "composer" ) local scene = composer.newScene() local feedbackNotif function scene:create( event ) local sceneGroup = self.view if(feedbackNotif) then notifications.cancelNotification(feedbackNotif) end local options = { alert = "Were you at " .. openapp.preferences.geo.name .. "? Leave your feedback!", badge = 0, custom = { target = "feedback" } } local utcTime = os.date( "!\*t", os.time() + 20 ) feedbackNotif = notifications.scheduleNotification( utcTime, options ) --feedbackNotif = notifications.scheduleNotification( 20, options ) --using this line stops warnings from appearing Runtime:addEventListener( "notification", onNotification ) end

Tried changing to the legacy plugin but that behaved exactly the same way so switched back as I hope to use firebase later in the project for push notifications.

I can’t work out what is causing all these issues, any help would be greatly appreciated!

Did you ever work out what was causing the warnings? 

My notifications do work, but I get those notifications saying invalid badge/alert/custom which makes me wonder if they will stop working in some circumstances.

We did not manage too fix this issue although the project that it was found in has since been abandoned. We’ll need to use notifications again in other projects coming up so if we can work out what went wrong i’ll be sure to update this.

Any further information on this notification issue?

i’m seeing something similar, we are using the require notifications v2 plugin. We are creating a business app with a local notification for a reminder to perform a task, the reminder (or notification date/time) is set by the user, looks like this. Our code:

(differenceInSec is calculation of two dates resulting in seconds between the two, that’s tested as working fine separately and data_entry_title textfield is fully accessible in scope and also tested as working with user input)

local utcTime = os.date("!\*t", os.time()+differenceInSec) local options = { alert = data\_entry\_title.text, badge = 1, custom = { show = "SchedulesView" } } notificationid = notifications.scheduleNotification( utcTime, options ) native.showAlert("APP NAME", notificationid .. " \<-- ID", {"OK"})

notificationid is created at the top of the lua file like this

local notificationid;

notificationid is NEVER returned, always nil - so I can’t cancel a notification ever. Of course I’d use Firebase but these notifications are per device and input as reminders per device - can I even schedule a device notification for push back via Firebase or is that meant to mass push notifications to device only?

Any help would be greatly appreciated.

Does this only happen when using UTC for the time and not local time?

Rob

Same result with utc, local and seconds to event.

Using a daily build, a week old I believe.

Any guidance would be great, I need to deliver an app with notifications and this is causing me a huge headache.

Thanks in advanced.

We will need a bug report on it. Also, have you looked at the Notifications sample app to see how we use the plugin?

The bug report will need to be a complete sample: main.lua, build.settings, config.lua and any assets that our engineers can use to build app, install it on a device and see the bug. It needs to be put in a .zip file and use the “Report a bug” link at the top of the page.

Rob

I’ll double check the sample and submit if I can’t get anywhere.

Thanks

@Rob I get this on Android 7 devices too.  Notifications only come in when the app is restarted (as stated above).  Same code works fine on devices before Android 7.

The sample app does work and I am using the same plugin and code is identical so I don’t get it.

The only difference is I call cancelNotification() in main.lua to cancel any outstanding notifications.

Bug filed - 11674836

Did you ever work out what was causing the warnings? 

My notifications do work, but I get those notifications saying invalid badge/alert/custom which makes me wonder if they will stop working in some circumstances.

We did not manage too fix this issue although the project that it was found in has since been abandoned. We’ll need to use notifications again in other projects coming up so if we can work out what went wrong i’ll be sure to update this.

Any further information on this notification issue?

i’m seeing something similar, we are using the require notifications v2 plugin. We are creating a business app with a local notification for a reminder to perform a task, the reminder (or notification date/time) is set by the user, looks like this. Our code:

(differenceInSec is calculation of two dates resulting in seconds between the two, that’s tested as working fine separately and data_entry_title textfield is fully accessible in scope and also tested as working with user input)

local utcTime = os.date("!\*t", os.time()+differenceInSec) local options = { alert = data\_entry\_title.text, badge = 1, custom = { show = "SchedulesView" } } notificationid = notifications.scheduleNotification( utcTime, options ) native.showAlert("APP NAME", notificationid .. " \<-- ID", {"OK"})

notificationid is created at the top of the lua file like this

local notificationid;

notificationid is NEVER returned, always nil - so I can’t cancel a notification ever. Of course I’d use Firebase but these notifications are per device and input as reminders per device - can I even schedule a device notification for push back via Firebase or is that meant to mass push notifications to device only?

Any help would be greatly appreciated.

Does this only happen when using UTC for the time and not local time?

Rob

Same result with utc, local and seconds to event.

Using a daily build, a week old I believe.

Any guidance would be great, I need to deliver an app with notifications and this is causing me a huge headache.

Thanks in advanced.

We will need a bug report on it. Also, have you looked at the Notifications sample app to see how we use the plugin?

The bug report will need to be a complete sample: main.lua, build.settings, config.lua and any assets that our engineers can use to build app, install it on a device and see the bug. It needs to be put in a .zip file and use the “Report a bug” link at the top of the page.

Rob

I’ll double check the sample and submit if I can’t get anywhere.

Thanks

@Rob I get this on Android 7 devices too.  Notifications only come in when the app is restarted (as stated above).  Same code works fine on devices before Android 7.

The sample app does work and I am using the same plugin and code is identical so I don’t get it.

The only difference is I call cancelNotification() in main.lua to cancel any outstanding notifications.

Bug filed - 11674836

Version 2022.3683 (2022.11.5), Android 12, Galaxy m12.
“plugin.notifications.v2”
The bug is still on.