Confirmed users
266
edits
Allstars.chh (talk | contribs) |
Allstars.chh (talk | contribs) |
||
Line 76: | Line 76: | ||
== Receiving NDEF messages, via MozActivity == | == 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 | 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'''" | 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. | If the NFC NDEF tag type is well known, such as URIs, the activity will be delievered with some extra fields already parsed. | ||
Line 94: | Line 94: | ||
navigator.mozSetMessageHandler('activity', NfcActivityHandler); | navigator.mozSetMessageHandler('activity', NfcActivityHandler); | ||
function NfcActivityHandler(activity) { | function NfcActivityHandler(activity) { | ||
var activityName = activity.source.name; | var activityName = activity.source.name; | ||
var data = activity.source.data; | var data = activity.source.data; | ||
switch (activityName) { | switch (activityName) { | ||
case 'nfc-ndef-discovered': | case 'nfc-ndef-discovered': | ||
console.log('nfc ndef message records(s): ' + JSON.stringify(data.records)); | console.log('nfc ndef message records(s): ' + JSON.stringify(data.records)); | ||
handleNdefDiscovered(data); | handleNdefDiscovered(data); | ||
break; | break; | ||
} | } | ||
} | } | ||
== Sending/Writing NDEF messages in P2P mode == | == Sending/Writing NDEF messages in P2P mode == |