Difference between revisions of "Notification"

From GiderosMobile
m (Text replacement - "</source>" to "</syntaxhighlight>")
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
 
 
<!-- GIDEROSOBJ:Notification -->
 
<!-- GIDEROSOBJ:Notification -->
'''<translate>Supported platforms</translate>:''' <br/>
+
'''Supported platforms:''' <br/>
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
+
'''Available since:''' Gideros 2011.6<br/>
=== <translate>Description</translate> ===
 
<translate>Notification class is used to compose and schedule new local notifications. You need to provide an ID of notification to constructor. Using same provided ID you can create a new instance of Notification class and modify existing notification with that ID. Additionally the ID allows you to identify local notification in the table of scheduled local notifications retrieved from [[Special:MyLanguage/NotificationManager:getScheduledNotifications|NotificationManager:getScheduledNotifications]], or table of local notifications that were already displayed using [[Special:MyLanguage/NotificationManager:getLocalNotifications|NotificationManager:getLocalNotifications]]
 
  
[[Special:MyLanguage/Notification|Notification]] consists of notification message, title, sound and number. Only message is the mandatory one. You can combine others as you wish.</translate>
+
=== Description ===
=== <translate>Examples</translate> ===
+
'''Notification''' class is used to compose and schedule new local notifications.
'''Create new notification and dispatch right away'''<br/>
+
 
<syntaxhighlight lang="lua">local note = Notification.new(1)
+
You need to provide an ID of notification to constructor. Using same provided ID you can create a new instance of Notification class and modify existing notification with that ID. Additionally the ID allows you to identify local notification in the table of scheduled local notifications retrieved from [[NotificationManager:getScheduledNotifications]], or table of local notifications that were already displayed using [[NotificationManager:getLocalNotifications]].
 +
 
 +
Notification consists of notification message, title, sound and number. Only message is the mandatory one. You can combine others as you wish.
 +
 
 +
=== Examples ===
 +
'''Create new notification and dispatch right away'''
 +
<syntaxhighlight lang="lua">
 +
local note = Notification.new(1)
 
note:setTitle("Notification app")
 
note:setTitle("Notification app")
 
note:setMessage("Do you see me?")
 
note:setMessage("Do you see me?")
 
note:setSound("./some_sound.wav")
 
note:setSound("./some_sound.wav")
note:dispatchNow()</syntaxhighlight>
+
note:dispatchNow()
'''Create new notification and dispatch after one hour with repeating period of one day'''<br/>
+
</syntaxhighlight>
<syntaxhighlight lang="lua">local note = Notification.new(2)
+
 
 +
'''Create new notification and dispatch after one hour with repeating period of one day'''
 +
<syntaxhighlight lang="lua">
 +
local note = Notification.new(2)
 
note:setTitle("Notification app")
 
note:setTitle("Notification app")
 
note:setMessage("I will bother you each day")
 
note:setMessage("I will bother you each day")
note:dispatchAfter({hour = 1}, {day = 1})</syntaxhighlight>
+
note:dispatchAfter({hour = 1}, {day = 1})
'''Create new notification and dispatch on specific date in specific time'''<br/>
+
</syntaxhighlight>
<syntaxhighlight lang="lua">local note = Notification.new(3)
+
 
 +
'''Create new notification and dispatch on specific date in specific time'''
 +
<syntaxhighlight lang="lua">
 +
local note = Notification.new(3)
 
note:setTitle("Notification app")
 
note:setTitle("Notification app")
 
note:setMessage("Happy Birthday")
 
note:setMessage("Happy Birthday")
note:dispatchOn({year = 2013, month = 8, day = 1, hour = 9, min = 0, sec = 0})</syntaxhighlight>
+
note:dispatchOn({year = 2013, month = 8, day = 1, hour = 9, min = 0, sec = 0})
'''Modifying existing scheduled notification'''<br/>
+
</syntaxhighlight>
<syntaxhighlight lang="lua">--id of notification to modify
+
 
 +
'''Modifying existing scheduled notification'''
 +
<syntaxhighlight lang="lua">
 +
--id of notification to modify
 
local id = 1
 
local id = 1
  
Line 44: Line 57:
 
--if we want to modify dispatch time we need to redispatch it
 
--if we want to modify dispatch time we need to redispatch it
 
note:dispatchAfter({day = 1})
 
note:dispatchAfter({day = 1})
end</syntaxhighlight>
+
end
 +
</syntaxhighlight>
 +
 
 
{|-
 
{|-
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
=== <translate>Methods</translate> ===
+
=== Methods ===
[[Special:MyLanguage/Notification.new|Notification.new]] ''<translate>creates new notification</translate>''<br/><!-- GIDEROSMTD:Notification.new() creates new notification -->
+
[[Notification.new]] ''creates new notification''<br/><!--GIDEROSMTD:Notification.new() creates new notification-->
[[Special:MyLanguage/Notification:cancel|Notification:cancel]] ''<translate>cancel notification</translate>''<br/><!-- GIDEROSMTD:Notification:cancel() cancel notification -->
+
[[Notification:cancel]] ''cancels notification''<br/><!--GIDEROSMTD:Notification:cancel() cancels notification-->
[[Special:MyLanguage/Notification:dispatchAfter|Notification:dispatchAfter]] ''<translate>Dispatch notification after specified time</translate>''<br/><!-- GIDEROSMTD:Notification:dispatchAfter() Dispatch notification after specified time -->
+
[[Notification:dispatchAfter]] ''dispatches notification after specified time''<br/><!--GIDEROSMTD:Notification:dispatchAfter() dispatches notification after specified time-->
[[Special:MyLanguage/Notification:dispatchNow|Notification:dispatchNow]] ''<translate>dispatch notification now</translate>''<br/><!-- GIDEROSMTD:Notification:dispatchNow() dispatch notification now -->
+
[[Notification:dispatchNow]] ''dispatches notification now''<br/><!--GIDEROSMTD:Notification:dispatchNow() dispatches notification now-->
[[Special:MyLanguage/Notification:dispatchOn|Notification:dispatchOn]] ''<translate>dispatch on specified date</translate>''<br/><!-- GIDEROSMTD:Notification:dispatchOn() dispatch on specified date -->
+
[[Notification:dispatchOn]] ''dispatches on specified date''<br/><!--GIDEROSMTD:Notification:dispatchOn() dispatches on specified date-->
[[Special:MyLanguage/Notification:getId|Notification:getId]] ''<translate>get id of notification</translate>''<br/><!-- GIDEROSMTD:Notification:getId() get id of notification -->
+
[[Notification:getId]] ''gets id of notification''<br/><!--GIDEROSMTD:Notification:getId() gets id of notification-->
[[Special:MyLanguage/Notification:getMessage|Notification:getMessage]] ''<translate>get message of notification</translate>''<br/><!-- GIDEROSMTD:Notification:getMessage() get message of notification -->
+
[[Notification:getMessage]] ''gets message of notification''<br/><!--GIDEROSMTD:Notification:getMessage() gets message of notification-->
[[Special:MyLanguage/Notification:getNumber|Notification:getNumber]] ''<translate>get notification number</translate>''<br/><!-- GIDEROSMTD:Notification:getNumber() get notification number -->
+
[[Notification:getNumber]] ''gets notification number''<br/><!--GIDEROSMTD:Notification:getNumber() gets notification number-->
[[Special:MyLanguage/Notification:getSound|Notification:getSound]] ''<translate>get sound of notification</translate>''<br/><!-- GIDEROSMTD:Notification:getSound() get sound of notification -->
+
[[Notification:getSound]] ''gets sound of notification''<br/><!--GIDEROSMTD:Notification:getSound() gets sound of notification-->
[[Special:MyLanguage/Notification:getTitle|Notification:getTitle]] ''<translate>get title of notification</translate>''<br/><!-- GIDEROSMTD:Notification:getTitle() get title of notification -->
+
[[Notification:getTitle]] ''gets title of notification''<br/><!--GIDEROSMTD:Notification:getTitle() gets title of notification-->
[[Special:MyLanguage/Notification:setNumber|Notification:setNumber]] ''<translate>set notification number</translate>''<br/><!-- GIDEROSMTD:Notification:setNumber() set notification number -->
+
[[Notification:setNumber]] ''sets notification number''<br/><!--GIDEROSMTD:Notification:setNumber() sets notification number-->
[[Special:MyLanguage/Notification:setSound|Notification:setSound]] ''<translate>set notification sound</translate>''<br/><!-- GIDEROSMTD:Notification:setSound() set notification sound -->
+
[[Notification:setSound]] ''sets notification sound''<br/><!--GIDEROSMTD:Notification:setSound() sets notification sound-->
[[Special:MyLanguage/Notification:setTitle|Notification:setTitle]] ''<translate>set the title of notification</translate>''<br/><!-- GIDEROSMTD:Notification:setTitle() set the title of notification -->
+
[[Notification:setTitle]] ''sets the title of notification''<br/><!--GIDEROSMTD:Notification:setTitle() sets the title of notification-->
 +
 
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
=== <translate>Events</translate> ===
+
=== Events ===
=== <translate>Constants</translate> ===
+
=== Constants ===
[[Special:MyLanguage/Notification.DEFAULT_SOUND|Notification.DEFAULT_SOUND]]<br/><!-- GIDEROSCST:Notification.DEFAULT_SOUND default-->
+
[[Notification.DEFAULT_SOUND]]<br/><!--GIDEROSCST:Notification.DEFAULT_SOUND default-->
 
|}
 
|}
 +
 +
{{GIDEROS IMPORTANT LINKS}}

Revision as of 00:22, 16 November 2025

Supported platforms:
Available since: Gideros 2011.6

Description

Notification class is used to compose and schedule new local notifications.

You need to provide an ID of notification to constructor. Using same provided ID you can create a new instance of Notification class and modify existing notification with that ID. Additionally the ID allows you to identify local notification in the table of scheduled local notifications retrieved from NotificationManager:getScheduledNotifications, or table of local notifications that were already displayed using NotificationManager:getLocalNotifications.

Notification consists of notification message, title, sound and number. Only message is the mandatory one. You can combine others as you wish.

Examples

Create new notification and dispatch right away

local note = Notification.new(1)
note:setTitle("Notification app")
note:setMessage("Do you see me?")
note:setSound("./some_sound.wav")
note:dispatchNow()

Create new notification and dispatch after one hour with repeating period of one day

local note = Notification.new(2)
note:setTitle("Notification app")
note:setMessage("I will bother you each day")
note:dispatchAfter({hour = 1}, {day = 1})

Create new notification and dispatch on specific date in specific time

local note = Notification.new(3)
note:setTitle("Notification app")
note:setMessage("Happy Birthday")
note:dispatchOn({year = 2013, month = 8, day = 1, hour = 9, min = 0, sec = 0})

Modifying existing scheduled notification

--id of notification to modify
local id = 1

--retrieve shared instance
local mngr = NotificationManager.getSharedInstance()

--retrieve table with scheduled notifications
local t = mngr:getScheduledNotifications()

--check if id is in it
if t[id] then
	--notification is still scheduled
	--let's modify it by creating new instance with same id
	local note = Notification.new(id)
	note:setTitle("New title")
	note:setMessage("New message")
	--if we want to modify dispatch time we need to redispatch it
	note:dispatchAfter({day = 1})
end

Methods

Notification.new creates new notification
Notification:cancel cancels notification
Notification:dispatchAfter dispatches notification after specified time
Notification:dispatchNow dispatches notification now
Notification:dispatchOn dispatches on specified date
Notification:getId gets id of notification
Notification:getMessage gets message of notification
Notification:getNumber gets notification number
Notification:getSound gets sound of notification
Notification:getTitle gets title of notification
Notification:setNumber sets notification number
Notification:setSound sets notification sound
Notification:setTitle sets the title of notification

Events

Constants

Notification.DEFAULT_SOUND