Warning Older Docs! - You are viewing documentation for a previous released version of RhoMobile Suite.

NFCManager API

Manage near field communications messages and records that your NFC application sends and receives. For code examples, see Rhodes Webinar Sample: NFC and Rhodes System API Samples: NFC.

As of Rhodes version 3.3.3, the Barcode, NFC, and Signature Capture APIs, as well as Rhom data encryption are removed from Rhodes. These features are only supported in Zebra RhoMobile Suite. If you wish to use these features, you will need to upgrade to RhoMobile Suite. Your application’s build.yml will also need to be modified to indicate the application type is ‘Rhoelements’. Additionally, a RhoElements license is required.

Enabling NFC

To use the NFC methods, you need to enable NFC on the Android device and ensure that the version is 2.3.3 or later. Do this by adding that capability to the build.yml file:

android: 
  version 2.3.3
  extensions:
  - nfc

Callback Tag Message Storage

The NFC callback stores the NFC tag messages in a hash array:

@params[‘messages’] - array of NFC tag messages. Each message is a hash.

The messages can be picked up in raw_message, an array of bytes containing the raw message. The messages can also be picked up in records, an array of records where each record is a hash. The records use the NFC Data Exchange Format. Each record has the following hash items.

raw_record Array of bytes. The raw record.
id Array of bytes. The tag ID.
payload Array of bytes. The tag payload.
tnf int. The Type Name Format.
type array of bytes
payload_as_string String. The message payload in a string (support special formats for URI, TEXT).
subrecords message hash (only for SMART_POSTER type)

is_supported

Returns true if the mobile device supports NFC, false otherwise.

Rho::NFCManager.is_supported

enable

The enable method enables NFC event processing on your mobile device. Your nfc and nfc_tech callback methods are executed only if Rhodes NFC is enabled. On Android, when Rhodes NFC is enabled and the application activity is in the foreground, the activity gets high priority for NFC events. Android will not show additional UI for the select Activity for Tag processing; the Rhodes application will process the tag.

Rho::NFCManager.enable

disable

Disables your application from receiving NFC events. Your application will not be able to receive NFC tags.

Rho::NFCManager.disable

is_enabled

Returns true if the mobile device has been enabled for NFC, false otherwise.

set_nfc_callback(callback_url)

Tells your application what callback to perform when it receives an NFC tag and your application is in the foreground. set_nfc_callback executes when the Android events ACTION_NDEF_DISCOVERED or ACTION_TAG_DISCOVERED are processed. Click here for an example in the Rhodes Developer Guide under NFC.

Rho::NFCManager.set_nfc_callback(callback_url)
callback_url String. The path to the method in the NFC controller that is executed on NFC callback.

set_nfc_tech_callback(callback_url)

Tells your application what callback to perform when it receives an NFC tag and your application is in the background. The set_nfc_tech_callback method executes when the Android event ACTION_TECH_DISCOVERED is processed. Click here for an example in the Rhodes Developer Guide under NFC.

Rho::NFCManager.set_nfc_tech_callback(callback_url)
callback_url String. The path to the method in the NFC controller that is executed on NFC callback.

get_current_Tag

Returns the current NFCTag that the mobile device has just read, or returns nil if no tag has been discovered. Click here for an example in the Rhodes Developer Guide under NFC.

Rho::NFCManager.get_current_Tag

perform_open_application_event

Call this method to have your application listen for NFC tags when it is in the background. When your application is in the background or it has not started, then the NFC event was saved, and the application open/start process is executed. To process that NFC event, your application needs to call perform_open_application_event, most likely from on_activate_app.

Rho::NFCManager.perform_open_application_event

p2p_enable_foreground_nde_push

The p2p_enable_foreground_nde_push method causes your mobile device to push an NFC message (NdefMessage) for any NFC-enabled device to receive. Click here for an example in the Rhodes Developer Guide under NFC.

Rho::NFCManager.p2p_enable_foreground_nde_push(NDefMessage)
NdefMessage The NFC message that is pushed.

p2p_disable_foreground_nde_push

Causes your mobile device to stop pushing NFC messages to any other NFC-enabled devices that can receive them. Click here for an example in the Rhodes Developer Guide under NFC.

Rho::NFCManager.p2p_disable_foreground_nde_push

make_NdefRecord_from_byte_array

Returns an NdefRecord for an NFC tag message.

Rho::NFCManager.make_NdefRecord_from_byte_array(array)
array a byte array containing a raw NFC record.

make_NdefRecord_from_hash

Returns an NdefRecord for an NFC tag message.

The make_NdefRecord_from_hash method creates a record for an NFC tag message (NdefRecord) from a hash.

Rho::NFCManager.make_NdefRecord_from_hash(hash)

Parameters

hash is either a tag event, as in @params[‘Tag_event’] - ‘discovered’, or an array of hashes, each of the following form:

id Array of bytes. The tag ID.
tnf Int. The Type Name Format.
type Array of bytes. The payload type.
payload Array of bytes. The message payload.

Example call:

hash = { 'id' => [0], 'type' => Rho::NdefRecord::RTD_URI, 'tnf' => Rho::NdefRecord::TNF_WELL_KNOWN, 'payload' => payload}
record = Rho::NFCManager.make_NdefRecord_from_hash(hash)

make_NdefMessage_from_byte_array

Returns an NFC tag message (NdefMessage) created from a byte array.

make_NdefMessage_from_byte_array(array)
array a byte array containing a raw NFC message.

make_NdefMessage_from_array_of_NdefRecord

Returns an NFC tag message (NdefMessage) created from an array of records (NdefRecord, such as what you get from make_NdefRecord_from_hash). Click here for an example in the Rhodes Developer Guide under NFC.

Rho::NFCManager.make_NdefMessage_from_array_of_NdefRecord(array)
array an array of records (NdefRecord).

make_string_from_payload

Returns a string from the payload of an NFC tag message record (NdefRecord).

Rho::NFCManager.make_string_from_payload(payload, tnf, type)
payload a byte array containing the payload.
tnf int. The Type Name Format. From NdefRecord.
type Array of bytes. The payload type. From NdefRecord.

make_payload_with_absolute_uri

Returns a byte array for an NFC record payload created from a string with an absolute URI.

Rho::NFCManager.make_payload_with_absolute_uri(uri_string)
uri_string a string containing an absolute URI, such as 'http://www.rhomobile.com'.

make_payload_with_well_known_uri

Returns a byte array for an NFC record payload from a string with an absolute URI. Click here for an example in the Rhodes Developer Guide under NFC.

Rho::NFCManager.make_payload_with_well_known_uri(prefix_code, uri_string)
prefix_code an int containing a prefix code.
uri_string a string containing an absolute URI, such as 'http://www.rhomobile.com'.

make_payload_with_well_known_text

Returns a byte array for an NFC record payload from a string language code and a string text.

Rho::NFCManager.make_payload_with_well_known_text(language, uri_string)
language a string containing a language code.
uri_string a string containing an absolute URI, such as 'http://www.rhomobile.com'.
Back to Top