Jorge Aviles
Jorge Aviles

Reputation: 13

NFC mobile credential on Phonegap

I'm trying dev a mobile app on Phonegap. This app send a tag, array or a string to an Arduino NFC Shield to then send again to a web service. How can I make the mobile as an tag NFC or something similar? I use all documentation from Phonegap-NFC but I don't get anything.

The index.js is modified like this:

var app = {
    initialize: function(){
    this.bindEvents();       
    },
    bindEvents: function(){
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    onDeviceReady: function(){
        app.receivedEvent('deviceready');
        var message = [
        ndef.textRecord("hello, world")
       ];

      nfc.share(message);
      }

};

This is what I recibe from Arduino.

NDEF Message 2 records, 102 bytes
  NDEF Record
    TNF 0x1 Well Known
    Type Length 0x1 1
    Payload Length 0x42 66
    Type 55  U
    Payload 03 70 6C 61 79 2E 67 6F 6F 67 6C 65 2E 63 6F 6D 2F 73 74 6F 72 65 2F 61 70 70 73 2F 64 65 74 61 69 6C 73 3F 69 64 3D 63 6F 6D 2E 73 6F 63 69 61 6C 2E 6E 66 63 26 66 65 61 74 75 72 65 3D 62 65 61 6D  .play.google.com/store/apps/details?id=com.social.nfc&feature=beam
    Record is 70 bytes
  NDEF Record
    TNF 0x4 External
    Type Length 0xF 15
    Payload Length 0xE 14
    Type 61 6E 64 72 6F 69 64 2E 63 6F 6D 3A 70 6B 67  android.com:pkg
    Payload 63 6F 6D 2E 73 6F 63 69 61 6C 2E 6E 66 63  com.social.nfc
    Record is 32 bytes
play.google.com/store/apps/details?id=com.social.nfc&feature=beam
Success

The Idea is:

Upvotes: 0

Views: 408

Answers (1)

doncoleman
doncoleman

Reputation: 2283

The NFC record you're seeing on the Arduino is default record generated by Android. This means there's probably a bug in your Javascript code. Try running jshint on index.js to track it down.

This sample project https://github.com/don/nfc-share should get you started with phonegap-nfc and sharing tags. If the default code sends a URI correctly, you can modify the code to send a Text Record

Replace https://github.com/don/nfc-share/blob/master/www/js/index.js#L41

nfc.share([ ndef.uriRecord("http://cordova.io") ], success, failure);

with

nfc.share([ ndef.textRecord("hello, world") ], success, failure);

Upvotes: 1

Related Questions