Post by lothcor on Dec 3, 2020 2:19:12 GMT
I am trying to implement NFC to write to tags, I can successfully read from multiple different tag types I have available but am having trouble getting the NdefRecord to be created correctly.
I am currently just trying to use the samples provided.
I understand that NFC hasn't been touched in a long time from the rhomobile team, but maybe someone could point me in the right direction?
Below you can see the hash being created with the payload getting set.
I understand that NFC hasn't been touched in a long time from the rhomobile team, but maybe someone could point me in the right direction?
Below you can see the hash being created with the payload getting set.
Any help here would be appreciated.
def start_nfc_push
puts "Sending #{@params['push'].inspect}..."
# prepare an NdefMessage for sending to another device
payload = Rho::NFCManager.make_payload_with_well_known_text('en', @params['push'])
# Create a hash -- id, tnf, type, payload -- for an NFC record
hash = { 'id' => [0], 'type' => Rho::NdefRecord::RTD_TEXT, 'tnf' => Rho::NdefRecord::TNF_WELL_KNOWN, 'payload' => payload}
puts hash
# Create the NFC record with that hash
record = Rho::NFCManager.make_NdefRecord_from_hash(hash)
records = [record]
msg = Rho::NFCManager.make_NdefMessage_from_array_of_NdefRecord(records)
tag = Rho::NFCManager.get_current_Tag
ndef = tag.get_tech(Rho::NFCTagTechnology::NDEF)
# start push message
if ndef != nil
ndef.connect
Rho::NFCTagTechnology_NfcV.transceive(msg)
puts ' finish write NdefMessage'
ndef.close
end
render :action => :index
end
2020-12-03 13:17:19.963 4824-4878/com.rhomobile.nfcrhodes I/APP: I 12/03/2020 13:17:19:963 96221920 HttpServer| Process URI: '/app/Nfc/start_nfc_push'
2020-12-03 13:17:20.004 4824-4878/com.rhomobile.nfcrhodes I/APP: I 12/03/2020 13:17:19:965 96221920 APP| RHO serve: /app/Nfc/start_nfc_push
2020-12-03 13:17:20.008 4824-4878/com.rhomobile.nfcrhodes I/APP: I 12/03/2020 13:17:20:008 96221920 APP| Params: {"push"=>"Hello from NFC!"}
2020-12-03 13:17:20.009 4824-4878/com.rhomobile.nfcrhodes I/APP: I 12/03/2020 13:17:20:008 96221920 APP| Sending "Hello from NFC!"...
2020-12-03 13:17:20.011 4824-4878/com.rhomobile.nfcrhodes I/APP: I 12/03/2020 13:17:20:010 96221920 APP| {"id"=>[0], "type"=>[84], "tnf"=>1, "payload"=>[2, 101, 110, 72, 101, 108, 108, 111, 32, 102, 114, 111, 109, 32, 78, 70, 67, 33]}
2020-12-03 13:17:20.012 4824-4878/com.rhomobile.nfcrhodes V/Nfc: ms[1606961840012] Exception during make NdefRecord from byte array !
2020-12-03 13:17:20.013 4824-4878/com.rhomobile.nfcrhodes W/System.err: android.nfc.FormatException: data too long
2020-12-03 13:17:20.013 4824-4878/com.rhomobile.nfcrhodes W/System.err: at android.nfc.NdefRecord.<init>(NdefRecord.java:594)
2020-12-03 13:17:20.013 4824-4878/com.rhomobile.nfcrhodes W/System.err: at com.rhomobile.nfc.NfcRecord.<init>(NfcRecord.java:28)
2020-12-03 13:17:20.013 4824-4878/com.rhomobile.nfcrhodes W/System.err: at com.rhomobile.nfc.Nfc.convert_byte_array_to_NdeRecord_hash(Nfc.java:955)