Android near-field communication-advanced NFC (1)

Source: Internet
Author: User

This article introduces some advanced NFC topics, such as a variety of NFC tag technologies, NFC tag compilation, and foreground scheduling. Foreground scheduling allows applications on the foreground to prioritize Intent event scheduling, even if there are other applications that filter the same Intent event.

NFC tag technology supported by Android

When NFC tags and Android devices are used for work, the main format of data read and write on NFC tags is NDEF. When the device scans data with NDEF, Android provides message parsing support and, if possible, sends it as an NdefMessage object. However, in some cases, the NFC tag scanned by the device does not contain NDEF data, or the NDEF data is not mapped to the MIME type or URI. In these cases, you need to open the communication with the NFC tag and use your own protocol (in the original byte format) to read and write it. Android uses the android. nfc. tech package to provide general support for these situations. This package is described in table 1 below. You can use the getTechList () method to determine the technologies supported by NFC tags, and use a class provided by android. nfc. tech to create corresponding TagTechnology objects.

Table 1. technologies supported by NFC tags

Class
Introduction
 
TagTechnology
All interfaces required by NFC tag technology.
 
NfcA
Provides access to NFC-A (ISO 14443-3A) attributes and I/O operations.
 
NfcB
Provides access to NFC-B (ISO 14443-3B) attributes and I/O operations.
 
NfcF
Provides access to NFC-F (ISO 6319-4) attributes and I/O operations.
 
NfcV
Provides access to NFC-V (ISO 15693) attributes and I/O operations.
 
IsoDep
Provides access to NFC-A (ISO 14443-4) attributes and I/O operations.
 
Ndef
Provides access to NDEF data and operations on NFC tags in the NDEF format.
 
NdefFormatable
Supports formatting NFC tags that can be formatted by NDEF.
 

Table 2. technologies supported by optional NFC tags

Class
Introduction
 
MifareClassic
If the Android device supports MIFARE, it provides access to the classic MIFARE type label attributes and I/O operations.
 
MifareUltralight
If the Android device supports MIFARE, it provides access to the slim mifare type label attributes and I/O operations.
 

 

NFC tag and ACTION_TECH_DISCOVERED Intent work together

When the device scans NFC tags with NDEF data but cannot map them to MIME or URI, the NFC tag scheduling system attempts to start an Activity using an ACTION_TECH_DISCOVERED Intent. When no NDEF data is found on the scanned NFC tag, Intent of the ACTION_TECH_DISCOVERED type is also used. With This rollback mechanism, if the scheduling system cannot parse the data for you, you can directly use the data on the NFC tag to work. The basic steps are as follows:

1. Specify the Intent filter of the ACTION_TECH_DISCOVERED type for the NFC tag you want to process. For more information, see NFC Intent filtering ". Generally, when an NDEF message cannot be mapped to a MIME type or URI, or the scanned NFC tag does not contain NDEF data, the NFC tag scheduling system starts an Intent of the ACTION_TECH_DISCOVERED type. For more information, see "NFC tag Scheduling System ".

2. When the application receives an Intent object, it obtains the Tag object from the Intent object:

Tag tagFromIntent = intent. getParcelableExtra (NfcAdapter. EXTRA_TAG );

3. Call a get factory method of the corresponding class in the android. nfc. tech package to obtain a TagTechnology object instance. Before calling the get factory method, call the getTechList () method to enumerate the technologies supported by NFC tags. For example, you can use the following method to obtain the MifareUltralight object instance from the Tag object:

MifareUltralight. get (intent. getParcelableExtra (NfcAdapter. EXTRA_TAG ));

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.