Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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