Notification Listener while app is running

Hi,

i would like to change the Badge to a different Number when a
Notification happen.

right now using

 local options = {  
 alert = "Pill Reminder",  
 badge = 1,  
 sound = "alert\_45.caf",  
 custom = { anythingYouWant = "My Days Rocks!" }  
 }  
 local myNotification = system.scheduleNotification( 2, options)  

it does set the badge only when the app is in the background.

While my app is in the foreground it would call

local function notificationListener( event )  
 -- display alert that shows the event name and type:  
 native.showAlert("My Days", "Take your Pill", { "OK" } )  
end  
Runtime:addEventListener( "notification", notificationListener )  

but would not change the Badge Number.

How would I make that the Badge Number of the Icon change, whatever the
app is in Foreground or Background?

In My case it would always happen when I Day change at 24:00 … if the
app is in foreground or background, doesn’t matter.

thx
chris
[import]uid: 4795 topic_id: 16399 reply_id: 316399[/import]

Stay tuned, in the works is an easier way of setting the badge count than what’s in place currently.

Keep a close eye on the Daily Build logs :slight_smile: [import]uid: 52430 topic_id: 16399 reply_id: 61239[/import]

Ok… looking forward :slight_smile: thanks for the Hint. [import]uid: 4795 topic_id: 16399 reply_id: 61275[/import]

hi. any news about

easier way of setting the badge count

?

:slight_smile:

chris
[import]uid: 4795 topic_id: 16399 reply_id: 70076[/import]

@chris: Yes, there is definitely an easier way to set a badge count (and also retrieve the current badge count). Here’s an example:

local badgeCount = native.getProperty( "applicationIconBadgeNumber" )badgeCount = badgeCount + 1native.setProperty( "applicationIconBadgeNumber", badgeCount )[/code]More information in this blog post:http://blog.anscamobile.com/2011/10/4-brand-new-apis-now-available/ [import]uid: 52430 topic_id: 16399 reply_id: 70077[/import]

how to change a badge when the app is in the background?

While app is in the background
local function notificationListener( event )
is not called and I can’t recalculate what Badge Number should be shown
(depending on Day and Time)

For now it does not make lot of sense when I only can change the badge
while the app is in the foreground.

Its like the Mail Icon on the iPhone Desktop would only change its
badge Number when the user does open the app.

Any Solution is welcome!!!

thx
chris
[import]uid: 4795 topic_id: 16399 reply_id: 73089[/import]

@guruk: Use:

native.setProperty( "applicationIconBadgeNumber", 11 )[/code]In the above example, 11 is what you want the icon badge to be. That's the easiest way to change your app's badge number.More information in this blog post:http://blog.anscamobile.com/2011/10/4-brand-new-apis-now-available/ [import]uid: 52430 topic_id: 16399 reply_id: 73115[/import]

Hi jonathanbeebe,
thanks for your enthusiasm to help.

also as mentioned. it need to be done while the app is running in the background !!

maybe i misunderstand, you may please give me a short example how you solve that!

by a thread or by a Notification Event.??? i tried both… and did not got it work.

thx
chris

[import]uid: 4795 topic_id: 16399 reply_id: 73124[/import]