Skip to content

Instantly share code, notes, and snippets.

@m00sey
Created September 10, 2011 01:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save m00sey/1207754 to your computer and use it in GitHub Desktop.
Save m00sey/1207754 to your computer and use it in GitHub Desktop.
Building an NFC enabled Android application with PhoneGap
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<data android:mimeType="my/mimetype" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<uses-permission android:name="android.permission.NFC" />
<uses-feature android:name="android.hardware.nfc" android:required="true" />
<uses-sdk android:minSdkVersion="10" />
nfc.addNdefListener(
writeTag,
function() {
console.log("Success.");
},
function() {
console.log("Fail.");
}
);
<script type="text/javascript" charset="utf-8" src="phonegap-nfc.js"></script>
nfc.addNdefListener(callback, [onSuccess], [onFailure]);
nfc.addNdefListener(
function() {
document.write("Found an NDEF formatted tag");
},
function() {
console.log("Success.");
},
function() {
console.log("Fail.");
}
);
nfc.addMimeTypeListener(mimeType, callback, [onSuccess], [onFailure]);
nfc.addMimeTypeListener(
"my/mimeType",
parseTag,
function() {
console.log("Success.");
} ,
function() {
console.log("Fail.");
}
);
function parseTag(nfcEvent) {
var records = nfcEvent.tagData;
for (var i = 0; i < records.length; i++) {
var record = records[i],
p = document.createElement('p');
p.innerHTML = nfc.bytesToString(record.payload);
display.appendChild(p);
}
}
<plugin name="NfcPlugin" value="com.chariotsolutions.nfc.plugin.NfcPlugin"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment