Event Broadcast and Subscription
The application can broadcast its own events to all listeners who want to listen. The events can either be predefined system events from the platform or user-defined events. Platform modules can broadcast system events whereas UI and service applications broadcast user-defined events.
The main features of the Event API are as follows:
-
Event publication
You can publish an event using the Tizen.Applications.EventManager.ApplicationEventManager class.
-
Event subscription
You can subscribe to an event using the Tizen.Applications.EventManager.EventReceiver class.
-
Launch-On-Events
You can launch the service applications when the desired target event occurs.
The application can be suspended while in the background, causing a pause in event handling. Since the application cannot receive events in the suspended state, they are all delivered in series after the application exits the suspended state. Following are the two methods to manage this situation and prevent the application from being flooded with events:
- To handle events in the background without going to a suspended state, declare a background category.
- To avoid receiving any events that are triggered while the application is suspended, remove the event handler before entering the suspended state and add it back after exiting the suspended state. You can manage the event handler addition and removal in the
APP_EVENT_SUSPENDED_STATE_CHANGEDevent callback, which is triggered each time the application enters and exist the suspended state.
Prerequisites
To enable your application to use the event functionality, follow these steps:
-
To use the methods and properties of the Tizen.Applications.EventManager.ApplcationManager and Tizen.Applications.EventManager.EventReceiver classes, include the Tizen.Applications.EventManager namespace in your application:
C#Copyusing Tizen.Applications.EventManager -
To use Launch-On-Events in your application, define the
http://tizen.org/appcontrol/operation/launch_on_eventoperation in thetizen-manifest.xmlfile.The URI name for the operation represents the event name in the Launch-On-Event format (
event://{Event_Name}):XMLCopy<app-control> <operation name="http://tizen.org/appcontrol/operation/launch_on_event"/> <uri name="event://tizen.system.event.battery_charger_status"/> </app-control>
Publish an event
To publish an event to all receivers, follow these steps:
-
Create the bundle for publishing the event data:
C#CopyBundle bundle = new Bundle(); bundle.AddItem("key", "value"); -
Use the
Publish()method to publish the event:C#CopyApplicationEventManager.Publish("event.org.tizen.example.AppEventTestApp.AppEvent", bundle);
Subscribe to an event
To subscribe to a predefined system event or user-defined event, follow these steps:
-
Add an event handler.
One event can have multiple event handlers, and one handler can be registered multiple times.
-
Add an event handler for a system event:
C#Copyvoid OnReceived(object sender, EventManagerEventArgs e) { LogUtils.Write(LogUtils.DEBUG, LOG_TAG, "On Received : " + e.Name); } /* Register the event handler */ EventReceiver receiver = new EventReceiver(SystemEvents.BatteryChargerStatus.EventName); receiver.Received += OnReceived; -
Add an event handler for a user-defined event:
When defining an event name for a user event such as
event.org.tizen.senderapp.user_event, the name format isevent.{sender appid}.{user-defined name}. The{user-defined name}must include the following:- Contain only the ASCII characters “[A-Z][a-z][0-9]_” and not begin with a digit.
- Not contain a ‘.’ (period) character.
- Not exceed the maximum name length (127 bytes).
- Be at least 1 byte in length.
C#CopyEventReceiver receiver = new EventReceiver("event.org.tizen.example.AppEventTestApp.AppEvent"); receiver.Received += OnReceived;
-
-
Remove the event handler when no longer needed.
A registered handler can be removed when the application is running. All the registered handlers can be removed when the application is terminated:
C#Copyreceiver.Received -= OnReceived;
Manage Launch-On-Events
To register an interest in a Launch-On-Event, define the http://tizen.org/appcontrol/operation/launch_on_event operation in the tizen-manifest.xml file.
NoteOnly service applications can register and receive Launch-On-Events.
The Launch-On-Event operation cannot be requested using the
AppControl.SendLaunchRequest()method, unlike other application control operations.
The following table shows the system events that support Launch-On-Event:
Table: System events supporting Launch-On-Event
| Name | Condition |
|---|---|
SystemEvents.BatteryChargerStatus.EventName |
When the charger state is SystemEvents.BatteryChargerStatus.StatusValueConnected. |
SystemEvents.UsbStatus.EventName |
When the USB state is SystemEvents.UsbStatus.StatusValueConnected. |
SystemEvents.EarjackStatus.EventName |
When the earjack state is SystemEvents.EarjackStatus.StatusValueConnected. |
SystemEvents.IncomingMsg.EventName |
When the SystemEvents.IncomingMsg.TypeKey and SystemEvents.IncomingMsg.IdKey exist. |
SystemEvents.WifiState.EventName |
When the Wi-Fi state is SystemEvents.WifiState.StateValueConnected. |
To receive the Launch-On-Event:
C#
Copy
void AppControlReplyReceivedCallback(Tizen.Applications.AppControl launchRequest, Tizen.Applications.AppControl replyRequest, AppControlReplyResult result)
{
string eventUri = "event://" + SystemEvents.BatteryChargerStatus.EventName;
if (launchRequest.Operation.Equals(SystemEvents.BatteryChargerStatus.EventName))
{
if (launchRequest.Uri.Equals(eventUri))
{
string batteryValue = launchRequest.ExtraData.Get(SystemEvents.BatteryChargerStatus.StatusKey);
LogUtils.Write(LogUtils.DEBUG, LOG_TAG, "Status value : " + batteryValue);
}
}
}
The application can get the event name and data in the first AppControlReplyCallback() callback, which is called after the application state changes to created.
Platform event types
The following list shows the events of modules:
-
capi-system-device
-
battery
You can scroll this table.Event name Event data key Event data value Condition Notes SystemEvents.BatteryChargerStatus.EventNameSystemEvents.BatteryChargerStatus.StatusKey- SystemEvents.BatteryChargerStatus.StatusValueDisconnected: Charger is not connected
-SystemEvents.BatteryChargerStatus.StatusValueConnected: Charger is connected
-SystemEvents.BatteryChargerStatus.StatusValueCharging: Charging is enabled
-SystemEvents.BatteryChargerStatus.StatusValueDischarging: Charging is disabled (for example, 100% full state)When the charger has been connected or disconnected, or when the charging state has changed (charging or not charging). If there is an earlier occurrence regarding this event, you receive the event as soon as you register an event handler for this event. You can use this earlier event data as the initial value. SystemEvents.BatteryLevelStatus.EventNameSystemEvents.BatteryLevelStatus.StatusKey- SystemEvents.BatteryLevelStatus.StatusValueEmpty
-SystemEvents.BatteryLevelStatus.StatusValueCritical
-SystemEvents.BatteryLevelStatus.StatusValueLow
-SystemEvents.BatteryLevelStatus.StatusValueHigh
-SystemEvents.BatteryLevelStatus.StatusValueFullWhen the battery level has changed. You can get the current value with the Tizen.System.Battery.Levelproperty.
-
-
deviced
-
usb
You can scroll this table.Event name Event data key Event data value Condition Notes SystemEvents.UsbStatus.EventNameSystemEvents.UsbStatus.StatusKey- SystemEvents.UsbStatus.StatusValueDisconnected: USB cable is not connected
-SystemEvents.UsbStatus.StatusValueConnected: USB cable is connected, but the service is not available
-SystemEvents.UsbStatus.StatusValueAvailable: USB service is available (for example, mtp or SDB)When the USB cable has been connected or disconnected, or when the USB service state has changed. N/A -
earjack
You can scroll this table.Event name Event data key Event data value Condition Notes SystemEvents.EarjackStatus.EventNameSystemEvents.EarjackStatus.StatusKey- SystemEvents.EarjackStatus.StatusValueDisconnected: Earjack is not connected
-SystemEvents.EarjackStatus.StatusValueConnected: Earjack is connectedWhen the earjack connection state has changed. You can get the current value using System.Information.SetCallbackwith thehttp://tizen.org/runtimefeature/audiojack.connectedkey. -
display
You can scroll this table.Event name Event data key Event data value Condition Notes SystemEvents.DisplayState.EventNameSystemEvents.DisplayState.StateKey- SystemEvents.DisplayState.StateValueNormal: Display on, normal brightness
-SystemEvents.DisplayState.StateValueDim: Display on, dimmed brightness
-SystemEvents.DisplayState.StateValueOff: Display offWhen the display state has changed. You can get the current value with the System.Display.Stateproperty.
-
-
systemd
-
system
You can scroll this table.Event name Event data key Event data value Condition Notes SystemEvents.BootCompleted.EventNameN/A N/A When the platform has completed booting. You can treat the initial value as falsebefore you receive this event. If the application is already in a boot-completed state before you register an event handler, you receive the event as soon as you register the event handler.SystemEvents.SystemShutdown.EventNameN/A N/A When the system power off has been started. You can treat the initial value as falsebefore you receive this event. If the application is already in a shutting-down state before you register an event handler, you receive the event as soon as you register the event handler.
-
-
resourced
-
ram memory
You can scroll this table.Event name Event data key Event data value Condition Notes SystemEvents.LowMemory.EventNameSystemEvents.LowMemory.Key- SystemEvents.LowMemory.ValueNormal: Available > 200MB
-SystemEvents.LowMemory.ValueSoftWarning: 100MB < available <= 200MB
-SystemEvents.LowMemory.ValueHardWarning: Available <= 100MB
Note
The above numbers can vary depending on the total RAM size of the target device.When the size of available memory has changed. If there is an earlier occurrence regarding this event, you receive the event as soon as you register an event handler for this event. You can use this earlier event data as the initial value.
-
-
network
-
connectivity
You can scroll this table.Event name Event data key Event data value Condition Notes SystemEvents.WifiState.EventNameSystemEvents.WifiState.StateKey- SystemEvents.WifiState.StateValueOn: Wi-Fi on
-SystemEvents.WifiState.StateValueOff: Wi-Fi off
-SystemEvents.WifiState.StateValueConnected: Wi-Fi connection establishedWhen the Wi-Fi state has changed. You can get the current value with the Network.Connection.ConnectionManager.WiFiStateproperty.SystemEvents.Btstate.EventNameSystemEvents.Btstate.StateKey- SystemEvents.Btstate.StateValueOff: Legacy Bluetooth off
-SystemEvents.Btstate.StateValueOn: Legacy Bluetooth onWhen the Bluetooth state has changed. You can get the current value with the Network.Bluetooth.BluetoothAdapter.IsBluetoothEnabledproperty.SystemEvents.Btstate.EventNameSystemEvents.Btstate.LeStateKey- SystemEvents.Btstate.LeStateValueOff: LE function off
-SystemEvents.Btstate.LeStateValueOn: LE function onWhen Bluetooth LE state has changed. - SystemEvents.Btstate.EventNameSystemEvents.Btstate.TransferStateKey- SystemEvents.Btstate.TransferStateValueNontransfering: Idle state
-SystemEvents.Btstate.TransferStateValueTransfering: File is transferringWhen the file transfer state has changed. -
-
-
libslp-location
-
location
You can scroll this table.Event name Event data key Event data value Condition Notes SystemEvents.LocatingEnableState.EventNameSystemEvents.LocatingEnableState.StateKey- SystemEvents.LocatingEnableState.StateValueDisabled: Location disabled
-SystemEvents.LocatingEnableState.StateValueEnabled: Location enabledWhen the location_enable_statehas changed, for example, by the user toggling the location setting in the settings menu or quick panel.You can get the current value with the Location.LocatorHelper.IsEnabledTypeproperty.SystemEvents.GpsEnableState.EventNameSystemEvents.GpsEnableState.StateKey- SystemEvents.GpsEnableState.StateValueDisabled: GPS disabled
-SystemEvents.GpsEnableState.StateValueEnabled: GPS enabledWhen the gps_enable_statehas changed.You can get the current value with the Location.LocatorHelper.IsEnabledTypeproperty.SystemEvents.NpsEnableState.EventNameSystemEvents.NpsEnableState.StateKey- SystemEvents.NpsEnableState.StateValueDisabled: NPS disabled
-SystemEvents.NpsEnableState.StateValueEnabled: NPS enabledWhen the NPS setting has changed, for example, by the user toggling the location settings. You can get the current value with the Location.LocatorHelper.IsEnabledTypeproperty.
-
-
msg-service
-
message
You can scroll this table.Event name Event data key Event data value Condition Notes SystemEvents.IncomingMsg.EventNameSystemEvents.IncomingMsg.TypeKey- SystemEvents.IncomingMsg.TypeValueSms: SMS-type message
-SystemEvents.IncomingMsg.TypeValueMms: MMS-type message
-SystemEvents.IncomingMsg.TypeValuePush: Push-type message
-SystemEvents.IncomingMsg.TypeValueCb: Cb-type messageWhen an SMS, MMS, push, or CB message has been received. - SystemEvents.IncomingMsg.EventNameSystemEvents.IncomingMsg.IdKeymsg_id: Message ID of the received message (string of the unsignedinttype value)- - SystemEvents.OutgoingMsg.EventNameSystemEvents.OutgoingMsg.TypeKey- SystemEvents.OutgoingMsg.TypeValueSms: SMS-type message
-SystemEvents.OutgoingMsg.TypeValueMms: MMS-type messageWhen an SMS or MMS message has been sent. - SystemEvents.OutgoingMsg.EventNameSystemEvents.OutgoingMsg.IdKeymsg_id: Message ID of the sent message (string of the unsignedinttype value)- -
-
-
alarm-manager
-
time
You can scroll this table.Event name Event data key Event data value Condition Notes SystemEvents.TimeChanged.EventNameN/A N/A When the system time setting has changed. You can get the current value with the Applications.AlarmManager.GetCurrentTimemethod.
-
-
setting
-
time
You can scroll this table.Event name Event data key Event data value Condition Notes SystemEvents.TimeZone.EventNameSystemEvents.TimeZone.KeyThe value of this key is the time zone value of the time zone database, for example, “Asia/Seoul”, “America/New_York”. For more information, see the IANA Time Zone Database. When the time zone has changed. You can get the current value with the System.SystemSettings.LocaleTimeZoneproperty. -
locale
You can scroll this table.Event name Event data key Event data value Condition Notes SystemEvents.HourFormat.EventNameSystemEvents.HourFormat.Key- SystemEvents.HourFormat.Value12
-SystemEvents.HourFormat.Value24When the hour_formathas changed, for example, by the user toggling the date and time settings for the 24-hour clock (where OFF stands for the 12-hour clock).You can get the current value with the System.SystemSettings.LocaleTimeFormat24HourEnabledproperty.SystemEvents.LanguageSet.EventNameSystemEvents.LanguageSet.KeyThe value of this key is the full name of the locale, for example, ko_KR.UTF8for Korean anden_US.UTF8for American English. For more information, see the Linux locale information.When the language_sethas changed.You can get the current value with the System.SystemSettings.LocaleLanguageproperty.SystemEvents.RegionFormat.EventNameSystemEvents.RegionFormat.KeyThe value of this key is the full name of the locale, for example, ko_KR.UTF8for the Korean region format anden_US.UTF8for the USA region format. For more information, see the Linux locale information.When the region_formathas changed.You can get the current value with the System.SystemSettings.LocaleCountryproperty. -
sound
You can scroll this table.Event name Event data key Event data value Condition Notes SystemEvents.SilentMode.EventNameSystemEvents.SilentMode.Key- SystemEvents.SilentMode.ValueOn
-SystemEvents.SilentMode.ValueOffWhen the ringtone has changed to 0 or another mode. For example, if the call slider has been changed to 0, silent_modeis"on". Otherwise,silent_modeis"off".You can get the current value with the System.SystemSettings.SoundSilentModeEnabledproperty. -
vibration
You can scroll this table.Event name Event data key Event data value Condition Notes SystemEvents.VibrationState.EventNameSystemEvents.VibrationState.StateKey- SystemEvents.VibrationState.StateValueOn
-SystemEvents.VibrationState.StateValueOffWhen the vibration state has changed. You can get the current value using System.Information.SetCallbackwith thehttp://tizen.org/runtimefeature/vibrationproperty. -
screen
You can scroll this table.Event name Event data key Event data value Condition Notes SystemEvents.AutoRotateState.EventNameSystemEvents.AutoRotateState.StateKey- SystemEvents.AutoRotateState.StateOn
-SystemEvents.AutoRotateState.StateOffWhen the screen autorotate state has changed, for example, by the user toggling the display settings. You can get the current value with the System.SystemSettings.DisplayScreenRotationAutoEnabledproperty. -
mobile
You can scroll this table.Event name Event data key Event data value Condition Notes SystemEvents.MobileDataState.EventNameSystemEvents.MobileDataState.StateKey- SystemEvents.MobileDataState.StateValueOn
-SystemEvents.MobileDataState.StateValueOffWhen the mobile data state has changed, for example, by the user toggling the network settings. You can get the current value with the System.SystemSettings.Data3GNetworkEnabledproperty.SystemEvents.DataRoamingState.EventNameSystemEvents.DataRoamingState.StateKey- SystemEvents.DataRoamingState.StateValueOn
-SystemEvents.DataRoamingState.StateValueOffWhen the data roaming state has changed, for example, by the user toggling the network settings. You can get the current value using System.Information.SetCallbackwith thehttp://tizen.org/runtimefeature/dataroamingkey. -
font
You can scroll this table.Event name Event data key Event data value Condition Notes SystemEvents.FontSet.EventNameSystemEvents.FontSet.KeyThe value of this key is the font name of the string type by font-config. When the font has changed. You can get the current value with the System.SystemSettings.FontTypeproperty.
-
Related information
- Dependencies
- Tizen 5.5 and Higher
- API References