Android 简明教程

Android - NFC Guide

NFC 是 Near Field Communication 的缩写,顾名思义,它提供了在两种兼容设备之间进行无线通信的机制。NFC 是一种短程无线技术,通信范围为 4 厘米或更短,用于两种设备共享数据。

NFC stands for Near Field Communication, and as the name implies it provides a wireless communication mechanism between two compatible devices. NFC is a short range wireless technology having a range of 4cm or less for two devices to share data.

How It Works

与蓝牙和 WiFi 等其他无线信号一样,NFC 也是基于通过无线电波发送信息的原理起作用的。通过 NFC,数据通过电子感应方式在两个设备间得以发送。

Like Bluetooth and WiFi, and all manner of other wireless signals, NFC works on the principle of sending information over radio waves. Through NFC data is send through electromagnetic induction between two devices.

NFC 工作基于标签,它允许你在 NFC 标签和 Android 设备或两种 Android 设备之间共享一定量的数据。标签有各种复杂性。存储在标签中的数据可以使用多种格式写入,但 Android API 基于 NFC 称为 NFC Data Exchange Format(NDEF). 的标准。

NFC works on the bases of tags , it allows you to share some amount of data between an NFC tag and an android powered device or between two android powered devices. Tags have various set of complexities. The Data stored in the tag can be written in a variety of formats, but android APIs are based around a NFC standard called as NFC Data Exchange Format(NDEF)..

NFC 跨数据传输的频率为 13.56 MHz,数据发送速率为 106、212 或 424 千比特每秒,足以进行一系列数据传输,从联系人信息到交换图片、歌曲和视频。

The transmission frequency for data across NFC is 13.56 megahertz, and data can be sent at either 106, 212 or 424 kilobits per second, which is quick enough for a range of data transfers from contact details to swapping pictures, songs and videos.

支持 NFC 的 Android 驱动设备支持以下三种主要操作模式 −

Android powered devices with NFC supports following three main modes of operations −

Three Modes of Operation

  1. Reader/Writer Mode − It allows the NFC device to read or write passive NFC tags.

  2. P2P mode − This mode allows NFC device to exchange data with other NFC peers.

  3. Card emulation mode − It allows the NFC device itself to act as an NFC card, so it can be accessed by an external NFC reader.

How it works with Android

要获取访问 NFC 硬件的权限,请在你的 Android.Manifest 文件中添加以下权限。

To get the permission to access NFC Hardware, add the following permission in your Android.Manifest file.

<uses-sdk android:minSdkVersion="10"/>

首先要注意的是,并非所有 Android 驱动设备都提供 NFC 技术。因此,为了确保你的应用仅对有 NFC 硬件的设备在谷歌应用商店中显示,请在你的 Android.Manifest 文件中添加以下行。

First thing to note is that not all android powered devices provide NFC technology. So to make sure that your application shows up in google play for only those devices that have NFC Hardware, add the following line in your Android.Manifest file.

<uses-feature android:name="android.hardware.nfc" android:required="true"/>

Android 提供了一个用于与其他设备通信的 android.nfc 包。该包包含以下类 −

Android provides a android.nfc package for communicating with another device. This package contains following classes −

Sr.No

Classes & Description

1

NdefMessage It represents an immutable NDEF Message.

2

NdefRecord It represents an immutable NDEF Record.

3

NfcAdapter It represents the local NFC adapter.

4

NfcEvent It wraps information associated with any NFC event.

5

NfcManager It is a high level manager used to obtain an instance of an NfcAdapter.

6

Tag It represents an NFC tag that has been discovered.

NFC 标签系统在 Android 中使用以下一些意图过滤器来工作:

NFC tags system works in android with the help of some intent filters that are listed below:

Sr.No

Filters & Features

1

ACTION_NDEF_DISCOVERED This intent is used to start an Activity when a tag contains an NDEF payload.

2

ACTION_TECH_DISCOVERED This intent is used to start an activity if the tag does not contain NDEF data, but is of known technology.

3

ACTION_TAG_DISCOVERED This intent is started if no activities handle the ACTION_NDEF_DISCOVERED or ACTION_TECH_DISCOVERED intents.

编码一个使用 NFC 技术的应用很复杂,因此除非必要,否则不要在你的应用中使用它。NFC 的使用在设备中并不常见,但它正在变得流行。让我们看看这项技术的未来 −

To code an application that uses NFC technology is complex so don’t use it in your app unless necessary. The use of NFC is not common in devices but it is getting popular. Let’s see what is the future of this technology −

Future Applications

随着这项技术日益发展,以及非接触式支付系统的引入,这项技术正得到蓬勃发展。一项称为 Google Wallet 的服务已经在美国推出,其目的是将我们的智能手机打造成信用卡和交通卡的可行替代品。

With this technology growing day by day and due to introduction of contact less payment systems this technology is getting a boom. A service known as Google Wallet is already introduced in the US which purpose is to make our smartphones a viable alternative to credit and transport cards.