Changes

Jump to: navigation, search

WebAPI/WebNFC

623 bytes removed, 06:43, 21 January 2015
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, although individual nfc tags can actually be compatible with multiple legacy and proprietary technology types.
Applications that do not have "'''nfc'''" read or write 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.
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));
console.log('Session Token: ' + JSON.stringify(data.sessionToken));
console.log('Technology Detected: ' + JSON.stringify(data.tech));
handleNdefDiscovered(data);
break;
}
}
 
'''Note''': Gaia applications, in order to read NDEF messages from a passive tag (or) P2P phone, should declare 'nfc-ndef-discovered' in their manifest file as stated above.This implies that the Gaia application that registered the 'nfc-ndef-discovered' activity shall be listed in activity picker whenever an NDEF message is about to be read.
== Sending/Writing NDEF messages in P2P mode ==
Confirm
266
edits

Navigation menu