Changes

Jump to: navigation, search

WebAPI/WebNFC

2,969 bytes removed, 06:51, 21 January 2015
Usage of APIs
= Usage of APIs =
== Receiving NDEF messages, via MozActivity ==Setup an Activity handler for incoming NDEF messages. The web activity chooser UI will route the messsage to the user selected application if there is more than one match. Currently, only NDEF is supported.  Applications that do not have "'''nfc'''" permissions can still get NDEF events via activities, and act on the data. The raw NDEF data is included with the activity, should the application wish to process any special properties of more complex NDEF data structures. If the NFC NDEF tag type is well known, such as URIs, the activity will be delievered with some extra fields already parsed. In the application manifest, declare the following in the activities block to get nfc ndef discovered events.  "nfc-ndef-discovered": { "filters": { "type": "url", "url": { "required":true, "regexp":"/^https?:.{1,16384}$/i" } } }, Then implement an activity handler in the application:   navigator.mozSetMessageHandler('activity', NfcActivityHandler); function NfcActivityHandler(activity) { var activityName = activity.source.name; var data = activity.source.data; switch (activityName) { case 'nfc-ndef-discovered': console.log('nfc ndef message records(s): ' + JSON.stringify(data.records)); handleNdefDiscovered(data); break; } } == Sending/Writing NDEF messages in P2P mode ==In P2P mode, there are two event listeners that can be registered by the applications. Applications should have 'nfc-write' permissions in order to register for 'onpeerready' and 'onpeerlost'.  '''1developer. onpeerready''' : Fired when there is another nfc peer phone is close proximity (in its near-field) and if the registered Nfc application is top-most (visible) applicationmozilla. Ex:- ''var nfcdom = window.navigator.mozNfc; nfcdom.onpeerready = function(event) { org// perform write ndef operation . }'''''2. onpeerlost''' : Fired when the fellow nfc peer has been taken away from its proximity (from its near-field) and if the registered Nfc application is top-most (visible) application. ''Ex:en- var nfcdom = window.navigator.mozNfc; nfcdom.onpeerlost = function(event) { US/docs/ If necessary, show an UI indication that device is lost. . }'' '''Note''': These above APIs 'onpeerready' and 'onpeerlost' should be used if the application wants to bypass the normal activity picker. As you may also have noted , for these event handlers to be fired, the Nfc Gaia application should be the top-visible Web/ foreground application.(There is no need to declare 'nfc-ndef-discovered' in the application's manifest file) == SendingAPI/Writing NDEF messages in Passive Tag mode =='''TBD''': Similar API needs to be added for a passive Tag scenario. foreground dispatch is still under discussion. {{bug|937430}} Gaia application that wants to perform write operation in a 'Passive Tag' mode, can still perform the action only after 'reading the ndef message via MozActivity' as stated in the above section.NFC_API
= Application Permissions =
Confirm
266
edits

Navigation menu