Created
September 10, 2011 01:01
-
-
Save m00sey/1207754 to your computer and use it in GitHub Desktop.
Building an NFC enabled Android application with PhoneGap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<intent-filter> | |
<action android:name="android.nfc.action.NDEF_DISCOVERED" /> | |
<data android:mimeType="my/mimetype" /> | |
<category android:name="android.intent.category.DEFAULT" /> | |
</intent-filter> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<uses-permission android:name="android.permission.NFC" /> | |
<uses-feature android:name="android.hardware.nfc" android:required="true" /> | |
<uses-sdk android:minSdkVersion="10" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nfc.addNdefListener( | |
writeTag, | |
function() { | |
console.log("Success."); | |
}, | |
function() { | |
console.log("Fail."); | |
} | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript" charset="utf-8" src="phonegap-nfc.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nfc.addNdefListener(callback, [onSuccess], [onFailure]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nfc.addNdefListener( | |
function() { | |
document.write("Found an NDEF formatted tag"); | |
}, | |
function() { | |
console.log("Success."); | |
}, | |
function() { | |
console.log("Fail."); | |
} | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nfc.addMimeTypeListener(mimeType, callback, [onSuccess], [onFailure]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nfc.addMimeTypeListener( | |
"my/mimeType", | |
parseTag, | |
function() { | |
console.log("Success."); | |
} , | |
function() { | |
console.log("Fail."); | |
} | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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