Android support for NFC technology
Android2.3.1 (API level = 9) started to support NFC technology, but android2.x and android3.x support for NFC is very limited. Starting with Android4.0 (API level = 14), Google started to force NFC, and NFC technology has gained further support in Android. In particular, Android4.1 can use NFC technology to deliver large amounts of data (NFC uses Bluetooth technology for large data transfers).
NFC Tag
different NFC tags vary greatly, some are very simple, only support simple read and write operations, and sometimes the use of a one-time write-enabled chip, the NFC tag is designed to read-only (write data only once, just like a normal burning disc). Of course, there are also some sophisticated NFC tags, for example, some NFC tags can be hardware-encrypted to restrict access to an area. There are also more "cool" NFC tags, which have their own operating environment, allowing NFC devices to interact with these tags more complex. The data in these tags will also be in a different format. But the Android SDK API primarily supports the NFC Forum standard, known as NDEF (NFC data exchange FORMAT,NFC Data Interchange Format).
Ndef operation of data
The Android SDK API supports the following 3 kinds of NDEF data operations.
Read NDEF format data from an NFC tag.
Writes data in NDEF format to an NFC tag.
Send ndef data to another NFC device via Android Beam technology.
Non-ndef data
for some special needs, the NDEF format may not meet our requirements, and you will need to use a non-NDEF data format. These data formats are actually normal byte streams, which are defined by the developer themselves as to what the data in the byte stream represents. This data format is called non-ndef data.
Triple filter mechanism for NFC
The NFC connection is established within 0.1 seconds before an NFC device reads data from an NFC tag or another NFC device, and then the data is automatically streamed from one end to the end of the read data (the NFC device typically needs to touch the screen to start the transmission). The data receiver invokes the corresponding activity (also known as Tag Dispatch) based on the specific data format and label type. These activity all need to define intent Filter. The intent filter specifies a different filtering mechanism, which is divided into 3 levels. Therefore, also known as the triple filtering mechanism of NFC.
# ndef_discovered: Filters only fixed-format NDEF data. For example, plain text, URIs for specified protocols (HTTP, FTP, SMB, etc.), and so on.
# Tech_discovered: This filtering mechanism is used to match when the filtering mechanism specified by action_ndef_discovered does not match the tag. This filtering mechanism is not matched by the data format in the tag, but by the data storage format supported by tag. This filtering mechanism is therefore more extensive.
# Tag_discovered: If the filtering mechanism of NFC is regarded as an if ... elseif...else statement, then this filtering mechanism is equivalent to the Else statement. After the previous two filtering mechanisms fail, this filtering mechanism is used to process the system. This filtering mechanism is used to process unrecognized tags (data format is not correct, and the format supported by tag does not match).
The Android system will match ndef_discovered, tech_discovered, and tag_discovered in turn. If the tag is still not matched by the triple filtering mechanism, nothing is done. Usually after the successful match tag, the Android device will emit a relatively crisp sound, and did not successfully match the tag, it will make a more dull sound.
1 <Activity2 Android:name=". Tagtextactivity "3 Android:label= "Show content for plain text NFC tags"4 Android:launchmode= "Singletask" >5 <Intent-filter>6 <!--ndef_discovered was specified -7 <ActionAndroid:name= "Android.nfc.action.NDEF_DISCOVERED" />8 <categoryAndroid:name= "Android.intent.category.DEFAULT" />9 <!--a plain text format is specified -Ten <DataAndroid:mimetype= "Text/plain" /> One </Intent-filter> A </Activity>
steps to write an NFC program
# Set permissions uses-permission android:name= "Android.permission.NFC"/>
# limit Android version <uses-sdk android:minsdkversion= "+"/>
# Limit installed devices <uses-feature android:name= "ANDROID.HARDWARE.NFC" android:required= "true"/>
# Define activity that can receive tags
# Processing business logic
Test the device required by the NFC program
two NFC-enabled phones or tabletsseveral NFC tags or stickers (readable and writable)
Major NFC-enabled models
Samsung Nexuss i9020Samsung Galaxys II i9101Samsung galaxynote i9220HTC G17Nexus 7/nexusNexus 4