Is it possible to read the nfc UID using PhoneGap? How?

I would like to read the NFC UID tag, the tags do not have an ndef message or anything (empty), just a UID . This is easy to do on Android, but developing Phonegap is much faster, so I would like to know if it can be made to work with Phonegap, perhaps using the phonegap-nfc plugin.

+4
source share
4 answers

The phonagap-nfc plugin will let you read the tag UID .

nfc.addTagDiscoveredListener() is good if you need a tag id. Starting with phonegap-nfc-0.4.0 , the tag identifier is also included in NDEF listeners when it is available.

You can convert the identifier to the sixth line for display with nfc.bytesToHexString(tag.id)

 function ready() { function onNfc(nfcEvent) { var tag = nfcEvent.tag; var tagId = nfc.bytesToHexString(tag.id); alert(tagId); } function win() { console.log("Listening for NFC Tags"); } function fail(error) { alert("Error adding NFC listener"); } nfc.addTagDiscoveredListener(onNfc, win, fail); } function init() { document.addEventListener('deviceready', ready, false); } 
+10
source

The answer to your question: yes, use the NFC plugin. Add a callback for any tag with nfc.addTagDiscoveredListener()

+1
source

I tried using the phonegap nfc plugin, the application works fine, without errors in the log, I get undefined whenever I read the UID tags.

0
source

How can nfc.addTagDiscoveredListener() accept 3 inputs, while in the code only two inputs are otherwise erroneous.

I add the solution above in the bottom function to read NFC identifiers, but it does not work.

This code is on the .ts homepage.

 public onReadClicked(): void { function onNfc(nfcEvent) { var tag = nfcEvent.tag; var tagId = this.nfc.bytesToHexString(tag.id); alert(tagId); } function win() { alert("Listening for NFC Tags"); } function fail(error) { alert("Error adding NFC listener"); } this.nfc.addTagDiscoveredListener(win, fail); } 

HTML side

 <p> <button ion-button full (click)="onReadClicked()"> Read NFC Device </button> </p> 
0
source

Source: https://habr.com/ru/post/1413826/


All Articles