SystemMessage API
System messages are messages from the system, they are sent by the system based on their types, for example, a system message with name alarm is sent to its subscriber when a timer goes off; a system message with name sms-received is sent when the system receives an sms message. SystemMessage API gives applications the ability to subscribe system messages of particular names, and events SystemMessageEvent
will dispatched to its registered ServiceWorker in different scenarios.
#
Message typesName | Permission |
---|---|
activity | |
alarm | alarms |
bluetooth-dialer-command | bluetooth-privileged |
bluetooth-map-request | bluetooth-privileged |
bluetooth-opp-receiving-file-confirmation | bluetooth-privileged |
bluetooth-opp-transfer-complete | bluetooth-privileged |
bluetooth-opp-transfer-start | bluetooth-privileged |
bluetooth-opp-update-progress | bluetooth-privileged |
bluetooth-pairing-aborted | bluetooth-privileged |
bluetooth-pairing-request | bluetooth-privileged |
bluetooth-pbap-request | bluetooth-privileged |
cellbroadcast-received | cellbroadcast |
data-sms-received | sms |
icc-stkcommand | settings:read, settings:write |
media-button | |
sms-delivery-error | sms |
sms-delivery-success | sms |
sms-failed | sms |
sms-received | sms |
sms-sent | sms |
system-time-change | system-time:read |
telephony-call-ended | telephony |
telephony-hac-mode-changed | telephony |
telephony-new-call | telephony |
telephony-tty-mode-changed | telephony |
ussd-received | mobileconnection |
wappush-received | wappush |
#
For front-end and application developersTo subscribe and receive system messages, an app has to have an active service worker.
#
Subscribe system messages from application manifestFirst, we need to specify the registration info of service worker in manifest, the format is as follows
The options
object is optional, as defined in ServiceWorkerContainer.register()#Syntax, for example:
In the most case the above example is good enough.
Second, subscribe the names of system messages in manifest.
Since now that system messages are dispatched to service worker, the field of target page
("/index.html" in the above example) in gecko48 does not affect the receiving of system messages.
#
Subscribe system messages from service workerApps can use SystemMessageManager.subscribe()
to subscribe system messages on an active service worker. systemMessageManager
is a property of ServiceWorkerRegistration
, which returns a reference to the SystemMessageManager
interface.
#
Use from main scripts#
Use from service worker script#
Receive system messagesSystem messages are delivered to the ServiceWorkerGlobalScope.onsystemmessage
event handler, in the format of SystemMessageEvent
.
- SystemMessageEvent
- name
- The type of this system message.
- data
- Returns an object
SystemMessageData
which wraps the details of this system message.
- SystemMessageData
- json()
- Extracts the message data as a JSON object, not available for activity messages.
- WebActivityRequestHandler()
- Only available for activity messages, details stated in
WebActivity API
.
#
For gecko developersSystemMessageService
provides an interface for module developers to send system messages to target applications, or broadcasting messages to all subscribers.
Syntax
Example