Class: Rho::NFCManager

Inherits:
Object show all
Defined in:
lib/extensions/nfc/nfc.rb

Class Method Summary collapse

Class Method Details

.disableObject

disable NFC event processing



680
681
682
# File 'lib/extensions/nfc/nfc.rb', line 680

def self.disable
    Nfc.enable(0)
end

.enableObject

enable NFC event processing (your nfc and nfc_tech callback executed only if Rhodes NFC enabled. Also for Android when Rhodes NFC enabled and application activity on foreground - activity get high priority for NFC events - in this case Android not show additional UI for select Activity for Tag processing - Tag processed by Rhodes application.



675
676
677
# File 'lib/extensions/nfc/nfc.rb', line 675

def self.enable
    Nfc.enable(1)
end

.get_current_TagObject

return current discovered Tag or nil if not any Tag discovered now



716
717
718
719
720
721
722
# File 'lib/extensions/nfc/nfc.rb', line 716

def self.get_current_Tag
     tech_list = Nfc.get_tech_list
     if tech_list.size == 0
         return nil
     end
     return NFCTag.new(tech_list)
end

.is_enabledObject

return true/false



685
686
687
688
# File 'lib/extensions/nfc/nfc.rb', line 685

def self.is_enabled
    e = Nfc.is_enabled
    return e != 0
end

.is_supportedObject

return true if current device supported NFC functionality



667
668
669
670
# File 'lib/extensions/nfc/nfc.rb', line 667

def self.is_supported
     s = Nfc.is_supported
     return s != 0
end

.make_NdefMessage_from_array_of_NdefRecord(array) ⇒ Object

make NdefMessage from NdefRecord[]



770
771
772
773
774
# File 'lib/extensions/nfc/nfc.rb', line 770

def self.make_NdefMessage_from_array_of_NdefRecord(array)
   msg = NdefMessage.new
   msg.init_from_array_of_NdefRecord(array) 
   return msg 
end

.make_NdefMessage_from_byte_array(array) ⇒ Object

make NdefMessage from byte[]



763
764
765
766
767
# File 'lib/extensions/nfc/nfc.rb', line 763

def self.make_NdefMessage_from_byte_array(array)
   msg = NdefMessage.new
   msg.init_from_byte_array(array) 
   return msg 
end

.make_NdefRecord_from_byte_array(array) ⇒ Object

make NdefRecord from byte[]



744
745
746
747
748
# File 'lib/extensions/nfc/nfc.rb', line 744

def self.make_NdefRecord_from_byte_array(array)
   rec = NdefRecord.new
   rec.init_from_byte_array(array) 
   return rec 
end

.make_NdefRecord_from_hash(hash) ⇒ Object

make NdefRecord from hash hash :

'id' - byte[]
'tnf' - int
'type' - byte[]
'payload' - byte[]


756
757
758
759
760
# File 'lib/extensions/nfc/nfc.rb', line 756

def self.make_NdefRecord_from_hash(hash)
   rec = NdefRecord.new
   rec.init_from_hash(hash) 
   return rec 
end

.make_payload_with_absolute_uri(uri_string) ⇒ Object

prepare byte[] payload from string with Absolute URI



784
785
786
# File 'lib/extensions/nfc/nfc.rb', line 784

def self.make_payload_with_absolute_uri(uri_string)
    return Nfc.make_payload_with_absolute_uri(uri_string)
end

.make_payload_with_well_known_text(language, text) ⇒ Object

prepare byte[] payload from string language code and string text



794
795
796
# File 'lib/extensions/nfc/nfc.rb', line 794

def self.make_payload_with_well_known_text(language, text)
    return Nfc.make_payload_with_well_known_text(language, text)
end

.make_payload_with_well_known_uri(prefix_code, uri_string) ⇒ Object

prepare byte[] payload from int prefix code and string URI



789
790
791
# File 'lib/extensions/nfc/nfc.rb', line 789

def self.make_payload_with_well_known_uri(prefix_code, uri_string)
    return Nfc.make_payload_with_well_known_uri(prefix_code, uri_string)
end

.make_string_from_payload(payload, tnf, type) ⇒ Object

make string from byte[] payload tnf - int (from NdefRecord) type - byte[] (from NdefRecord)



779
780
781
# File 'lib/extensions/nfc/nfc.rb', line 779

def self.make_string_from_payload(payload, tnf, type)
   return Nfc.make_string_from_payload(payload, tnf, type)
end

.p2p_disable_foreground_nde_pushObject

stop any push NdefMessage to receivers



738
739
740
# File 'lib/extensions/nfc/nfc.rb', line 738

def self.p2p_disable_foreground_nde_push
    Nfc.p2p_disable_foreground_nde_push
end

.p2p_enable_foreground_nde_push(ndef_message) ⇒ Object

ndef_message - NdefMessage start push NdefMessage to any receivers



733
734
735
# File 'lib/extensions/nfc/nfc.rb', line 733

def self.p2p_enable_foreground_nde_push(ndef_message)
    Nfc.p2p_enable_foreground_nde_push(ndef_message.get_byte_array)
end

.perform_open_application_eventObject

call this function after application is started and you setup all functionality for process NFC event when application in background or not started, then NFC event was saved and application open/start process executed for process saved event - call this function



727
728
729
# File 'lib/extensions/nfc/nfc.rb', line 727

def self.perform_open_application_event
    Nfc.perform_open_application_event
end

.set_nfc_callback(callback_url) ⇒ Object

set callback for NFC NdefMessage events in callback @params - array of messages (each message is hash) message hash items :

'raw_message' - array of bytes (raw message)
'records' - array of records (each record is hash)
       record hash items :
              'raw_record' - array of bytes (raw record)
              'id' - array of bytes
              'payload' - array of bytes
              'tnf' - int
              'type' - array of bytes 
              'payload_as_string' - string, payload prepared to string (support specail formats for URI, TEXT) 
              'subrecords' - message hash (only for SMART_POSTER type)


704
705
706
# File 'lib/extensions/nfc/nfc.rb', line 704

def self.set_nfc_callback(callback_url)
     Nfc.set_callback(callback_url)
end

.set_nfc_tech_callback(callback_url) ⇒ Object

set callback for NFC Tech events in callback @params - ‘discovered’



711
712
713
# File 'lib/extensions/nfc/nfc.rb', line 711

def self.set_nfc_tech_callback(callback_url)
     Nfc.set_tech_callback(callback_url)
end