# Local notification problems when testing on android

**URL:** <https://forums.solar2d.com/t/local-notification-problems-when-testing-on-android/344530>\
**Category:** Newbie Questions\
**Created:** [June 27, 2017, 12:20pm UTC](https://forums.solar2d.com/t/local-notification-problems-when-testing-on-android/344530 "2017-06-27T12:20:24Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ProbablyRational](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/p/4da419/32.png) [@ProbablyRational](https://forums.solar2d.com/u/ProbablyRational)\
**Post date:** [June 27, 2017, 12:20pm UTC](https://forums.solar2d.com/t/local-notification-problems-when-testing-on-android/344530/1 "2017-06-27T12:20:24Z")

</div>

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 &nbsp;: WARNING: notifications.scheduleNotification(time [, options]), Invalid option ‘badge’
> 
> 06-27 12:56:21.387 19257 19277 I Corona &nbsp;: WARNING: notifications.scheduleNotification(time [, options]), Invalid option ‘alert’
> 
> 06-27 12:56:21.387 19257 19277 I Corona &nbsp;: WARNING: notifications.scheduleNotification(time [, options]), Invalid option ‘custom’

The notification then does not appear after the set time. &nbsp;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. &nbsp;On top of this, when I tap the notification the app does not open. &nbsp;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 ) &nbsp;&nbsp;&nbsp;&nbsp;print( event.name ) &nbsp;&nbsp;&nbsp;&nbsp;if ( event.custom ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print( event.custom.foo ) &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;if ( event.type == "local" ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-- Handle the local notification &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local badgeNum = native.getProperty( "applicationIconBadgeNumber" ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( badgeNum \> 0 ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;badgeNum = badgeNum - 1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;native.setProperty( "applicationIconBadgeNumber", badgeNum ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;elseif ( event.type == "remote" ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-- Handle the push notification &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( event.badge and event.badge \> 0 ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;native.setProperty( "applicationIconBadgeNumber", event.badge - 1 ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;end end Runtime:addEventListener( "notification", onNotification ) &nbsp;&nbsp;&nbsp; &nbsp; if ( launchArgs and launchArgs.notification ) then &nbsp;&nbsp;&nbsp;&nbsp;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!

---

<div class="post-metadata">

**Author:** ![Alan\_PlantPot](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/a/58956e/32.png) [@Alan\_PlantPot](https://forums.solar2d.com/u/Alan_PlantPot)\
**Post date:** [October 17, 2017, 9:25am UTC](https://forums.solar2d.com/t/local-notification-problems-when-testing-on-android/344530/2 "2017-10-17T09:25:50Z")

</div>

Did you ever work out what was causing the warnings?&nbsp;

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.

---

<div class="post-metadata">

**Author:** ![ProbablyRational](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/p/4da419/32.png) [@ProbablyRational](https://forums.solar2d.com/u/ProbablyRational)\
**Post date:** [October 19, 2017, 8:07am UTC](https://forums.solar2d.com/t/local-notification-problems-when-testing-on-android/344530/3 "2017-10-19T08:07:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Milner99](https://forums.solar2d.com/user_avatar/forums.solar2d.com/milner99/32/2091_2.png) [@Milner99](https://forums.solar2d.com/u/Milner99)\
**Post date:** [November 23, 2017, 3:06pm UTC](https://forums.solar2d.com/t/local-notification-problems-when-testing-on-android/344530/4 "2017-11-23T15:06:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rob](https://forums.solar2d.com/user_avatar/forums.solar2d.com/rob/32/4_2.png) [@rob](https://forums.solar2d.com/u/rob)\
**Post date:** [November 23, 2017, 8:43pm UTC](https://forums.solar2d.com/t/local-notification-problems-when-testing-on-android/344530/5 "2017-11-23T20:43:39Z")

</div>

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

Rob

---

<div class="post-metadata">

**Author:** ![Milner99](https://forums.solar2d.com/user_avatar/forums.solar2d.com/milner99/32/2091_2.png) [@Milner99](https://forums.solar2d.com/u/Milner99)\
**Post date:** [November 23, 2017, 8:54pm UTC](https://forums.solar2d.com/t/local-notification-problems-when-testing-on-android/344530/6 "2017-11-23T20:54:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rob](https://forums.solar2d.com/user_avatar/forums.solar2d.com/rob/32/4_2.png) [@rob](https://forums.solar2d.com/u/rob)\
**Post date:** [November 23, 2017, 9:06pm UTC](https://forums.solar2d.com/t/local-notification-problems-when-testing-on-android/344530/7 "2017-11-23T21:06:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Milner99](https://forums.solar2d.com/user_avatar/forums.solar2d.com/milner99/32/2091_2.png) [@Milner99](https://forums.solar2d.com/u/Milner99)\
**Post date:** [November 23, 2017, 9:20pm UTC](https://forums.solar2d.com/t/local-notification-problems-when-testing-on-android/344530/8 "2017-11-23T21:20:15Z")

</div>

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

Thanks

---

<div class="post-metadata">

**Author:** ![anon63346430](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/a/6a8cbe/32.png) [@anon63346430](https://forums.solar2d.com/u/anon63346430)\
**Post date:** [November 24, 2017, 6:51pm UTC](https://forums.solar2d.com/t/local-notification-problems-when-testing-on-android/344530/9 "2017-11-24T18:51:16Z")

</div>

@Rob I get this on Android 7 devices too.&nbsp; Notifications only come in when the app is restarted (as stated above).&nbsp; 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.

---

<div class="post-metadata">

**Author:** ![anon63346430](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/a/6a8cbe/32.png) [@anon63346430](https://forums.solar2d.com/u/anon63346430)\
**Post date:** [November 25, 2017, 5:41pm UTC](https://forums.solar2d.com/t/local-notification-problems-when-testing-on-android/344530/10 "2017-11-25T17:41:46Z")

</div>

Bug filed -&nbsp;11674836

---

<div class="post-metadata">

**Author:** ![Alan\_PlantPot](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/a/58956e/32.png) [@Alan\_PlantPot](https://forums.solar2d.com/u/Alan_PlantPot)\
**Post date:** [October 17, 2017, 9:25am UTC](https://forums.solar2d.com/t/local-notification-problems-when-testing-on-android/344530/11 "2017-10-17T09:25:50Z")

</div>

Did you ever work out what was causing the warnings?&nbsp;

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.

---

<div class="post-metadata">

**Author:** ![ProbablyRational](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/p/4da419/32.png) [@ProbablyRational](https://forums.solar2d.com/u/ProbablyRational)\
**Post date:** [October 19, 2017, 8:07am UTC](https://forums.solar2d.com/t/local-notification-problems-when-testing-on-android/344530/12 "2017-10-19T08:07:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Milner99](https://forums.solar2d.com/user_avatar/forums.solar2d.com/milner99/32/2091_2.png) [@Milner99](https://forums.solar2d.com/u/Milner99)\
**Post date:** [November 23, 2017, 3:06pm UTC](https://forums.solar2d.com/t/local-notification-problems-when-testing-on-android/344530/13 "2017-11-23T15:06:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rob](https://forums.solar2d.com/user_avatar/forums.solar2d.com/rob/32/4_2.png) [@rob](https://forums.solar2d.com/u/rob)\
**Post date:** [November 23, 2017, 8:43pm UTC](https://forums.solar2d.com/t/local-notification-problems-when-testing-on-android/344530/14 "2017-11-23T20:43:39Z")

</div>

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

Rob

---

<div class="post-metadata">

**Author:** ![Milner99](https://forums.solar2d.com/user_avatar/forums.solar2d.com/milner99/32/2091_2.png) [@Milner99](https://forums.solar2d.com/u/Milner99)\
**Post date:** [November 23, 2017, 8:54pm UTC](https://forums.solar2d.com/t/local-notification-problems-when-testing-on-android/344530/15 "2017-11-23T20:54:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rob](https://forums.solar2d.com/user_avatar/forums.solar2d.com/rob/32/4_2.png) [@rob](https://forums.solar2d.com/u/rob)\
**Post date:** [November 23, 2017, 9:06pm UTC](https://forums.solar2d.com/t/local-notification-problems-when-testing-on-android/344530/16 "2017-11-23T21:06:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Milner99](https://forums.solar2d.com/user_avatar/forums.solar2d.com/milner99/32/2091_2.png) [@Milner99](https://forums.solar2d.com/u/Milner99)\
**Post date:** [November 23, 2017, 9:20pm UTC](https://forums.solar2d.com/t/local-notification-problems-when-testing-on-android/344530/17 "2017-11-23T21:20:15Z")

</div>

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

Thanks

---

<div class="post-metadata">

**Author:** ![anon63346430](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/a/6a8cbe/32.png) [@anon63346430](https://forums.solar2d.com/u/anon63346430)\
**Post date:** [November 24, 2017, 6:51pm UTC](https://forums.solar2d.com/t/local-notification-problems-when-testing-on-android/344530/18 "2017-11-24T18:51:16Z")

</div>

@Rob I get this on Android 7 devices too.&nbsp; Notifications only come in when the app is restarted (as stated above).&nbsp; 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.

---

<div class="post-metadata">

**Author:** ![anon63346430](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/a/6a8cbe/32.png) [@anon63346430](https://forums.solar2d.com/u/anon63346430)\
**Post date:** [November 25, 2017, 5:41pm UTC](https://forums.solar2d.com/t/local-notification-problems-when-testing-on-android/344530/19 "2017-11-25T17:41:46Z")

</div>

Bug filed -&nbsp;11674836

---

<div class="post-metadata">

**Author:** ![max.srdk](https://forums.solar2d.com/user_avatar/forums.solar2d.com/max.srdk/32/69_2.png) [@max.srdk](https://forums.solar2d.com/u/max.srdk)\
**Post date:** [November 22, 2022, 12:26am UTC](https://forums.solar2d.com/t/local-notification-problems-when-testing-on-android/344530/20 "2022-11-22T00:26:36Z")

</div>

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