Android NFC framework introduction and develop guide(2)
发布时间:2021-06-07
发布时间:2021-06-07
Android system NFC framework introduction and develop guide
The Tag Dispatch System
Android-powered devices are usually looking for NFC tags when the screen is unlocked, unless NFC is disabled in the device's Settings menu. When an Android-powered device discovers an NFC tag, the desired behavior is to have the most appropriate activity handle the intent without asking the user what application to use. Because devices scan NFC tags at a very short range, it is likely that making users manually select an activity would force them to move the device away from the tag and break the connection. You should develop your activity to only handle the NFC tags that your activity cares about to prevent the Activity Chooser from appearing.
To help you with this goal, Android provides a special tag dispatch system that analyzes scanned NFC tags, parses them, and tries to locate applications that are interested in the scanned data. It does this by:
1. Parsing the NFC tag and figuring out the MIME type or a URI that identifies the data
payload in the tag.
2. Encapsulating the MIME type or URI and the payload into an intent. These first two steps
are described in How NFC tags are mapped to MIME types and URIs.
3. Starts an activity based on the intent. This is described in How NFC Tags are Dispatched
to Applications.
How NFC tags are mapped to MIME types and URIs
Before you begin writing your NFC applications, it is important to understand the different types of NFC tags, how the tag dispatch system parses NFC tags, and the special work that the tag dispatch system does when it detects an NDEF message. NFC tags come in a wide array of technologies and can also have data written to them in many different ways. Android has the NDEF data is encapsulated inside a message (NdefMessage) that contains one or more records (NdefRecord). Each NDEF record must be well-formed according to the specification of the type of record that you want to create. Android also supports other types of tags that do not contain NDEF data, which you can work with by using the classes in the android.nfc.tech package. types of tags involves writing your own protocol stack to communicate with the tags, so we recommend using NDEF when possible for ease of development and maximum support for Android-powered devices.
Note:to construct NDEF records.
下一篇:上半年工作总结