Android NFC Program Design

Source: Internet
Author: User

NFC Overview

NFC is short for Near Field Communication, which is short for Near-range wireless Communication technology. NFC, jointly developed by Philips and Sony, is a non-

Contact identification and interconnection technologies can be used in mobile devices, consumer electronic products,

Provides close-range wireless communication between PCs and smart control tools.

13.56MHz frequency runs within 20 cm. The transmission speed is 106 Kbit/second, 212 Kbit/second, or 424 Kbit/second. Currently, near-field communication is enabled.

ISO/iec is 18092 international standard, ECMA-340 standard and ETSI

TS 102 190 standard. NFC adopts active and passive communication modes.

Mobile phone NFC supports three working modes: read/write tag mode, point-to-point mode, and card simulation mode.


Basic NFC classes

The Android platform provides two android. nfc and android. nfc. tech packages with APIs to implement NFC tag operations.

The android. nfc package has four main categories:

NfcManager class:It can be used to manage all NFC adapters specified in Android devices. However, most Android devices only support one NFC Adapter.

You can use the getDefaultAapater method to obtain the system-supported Adapter.

NfcAdapter class:The NFC adapter of this device can define the Intent to request the system to send the tags notification to your Activity and provide

To register the front-end tag reminder release and front-end NDEF push.

NdefMessage class:NDEF is a data structure defined by the NFC forum. It is used to effectively store data into tags, such as text, URL, and other MIME classes.

Type. An NdefMessage acts as a container that stores the sent and read data. An NdefMessage object contains 0 or more

NdefRecord. Each NDEF record has a type, such as text, URL, smart poster/advertisement, or other MIME data. In

The first NfcRecord type in NDEFMessage is used to send tags to an activity on an android device.

Tag class:Identifies a passive NFC target, such as tag, card, key hook, or even an NFC card simulated by phone. Tag

Method.

Android. nfc. tech package

Android. nfc. tech Contains classes that query tag attributes and perform I/O operations. These classes indicate different NFC technical standards supported by a tag.

TagTechnology:This interface is required by all the tag technology classes below.

NfcA:Supports attributes and I/O operations of ISO 14443-3A.

NfcB:Properties and I/O operations for NFC-B (ISO 14443-3B.

NfcF:NFC-F (JIS 6319-4) properties and I/O operations.

NfcV:Properties and I/O operations for NFC-V (ISO 15693.

IsoDep:Properties and I/O operations for ISO-DEP (ISO 14443-4.

Ndef:Read and Write tags that support NDEF format.

NdefFormatable:Provides a formatting operation for tags that can be formatted into NDEF format.

MifareClassic:If the android device supports MIFARE, it provides attributes and I/O operations for the MIFARE Classic target.

MifareUltralight:If the android device supports MIFARE, it provides attributes and I/O operations for the MIFARE Ultralight target.


NFC programming procedure

Set permissions

Version limit

Restrict installed devices

Define the Activity that can receive tags (information about tags can be obtained)

Processing Business (based on the specific business signature)


NFC tag filtering system

Android

Device.

Public void connect (): Enable I/O operations to the tag from this TagTechnology object.

Public void format (NdefMessage firstMessage): Format a tag as NDEF, and write a NdefMessage.


NFC frontend Scheduling

Give the right to process NFC tags to a window (with the highest priority)

1. Obtain the NfcAdapter object in onCreate;

2. Create the PendingIntent associated with the Activity;

3. Specify a window for processing NFC tags. Generally, nfcAdapter. enableForegroundDispatch () is used in the onResume () method ()

;

4. Disable window processing of NFC tags. Use nfcAdapter. disableForegroundDispatch.


Permission settings

Before you can access the NFC hardware of a device and properly process the NFC Intent, You need to declare the following items in AndroidManifest. xml:

1. NFC usage Elements to access NFC hardware:

2. The minimum SDK version must be set correctly. API level 9 only supports a limited number of tags. API level 10 is used to provide extensive read/write support for tags.

3. uses-feature Element Definition: Your program can display NFC hardware in the android Market.

4. The NFC intent filter tells the android system that your activity can process NFC data. One or more intent filters can be defined.



Related Article

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.