37
Speaker: 陳陳陳 GitHub: https:// github.com/matisse11235813/AndroidNFC NFC Tutorial

Nfc tutorial

Embed Size (px)

Citation preview

Page 1: Nfc tutorial

Speaker: 陳柏伸GitHub: https://github.com/matisse11235813/AndroidNFC

NFC Tutorial

Page 2: Nfc tutorial

Outline• Background knowledge• DEMO• 實作一個 NFC Tag Reader• 實作一個 NFC Tag Writer• 小結• References

Page 3: Nfc tutorial

Near Field Communication , NFC• 近場通訊(英語: Near Field Communication , NFC ),又稱近距離無線通訊,是一種短距離的高頻無線通訊技術,允許電子裝置之間進行非接觸式點對點資料傳輸,在十公分( 3.9 英吋)內交換資料。• 這個技術由非接觸式射頻識別( RFID)演變而來,由飛利浦半導體(現恩智浦半導體)、諾基亞和索尼共同研製開發。

Page 4: Nfc tutorial

不同通訊技術比較近場通訊是一種短距高頻的無線電技術,在 13.56MHz 頻率運行。其傳輸速度最高可達 424 Kbit/ 秒。目前近場通訊已通過成為 ISO/IEC IS 18092 國際標準、 EMCA-340 標準與 ETSI TS 102 190標準。

Page 5: Nfc tutorial

NFC 的工作模式• NFC 卡片模擬模式 (card emulation mode)• 點對點模式 (peer-to-peer mode) • 讀寫模式 (reader/writer mode)

Page 6: Nfc tutorial

NFC 卡片模擬模式• NFC 可模擬 RFID 機體電路 (IC) 卡,搭配安全模組,可讓使用者安全地進行交易。可以替代現在大量的 IC 卡(包括信用卡)場合商場刷卡、 IPASS 、門禁管制、車票、門票等等。

Page 7: Nfc tutorial

點對點模式• 可透過 NFC 連線在不同的 NFC 裝置之間分享名片等資訊。也能透過 NFC 連線快速設定 WiFi* 或藍牙 * 連線,再以 WiFi 或藍牙連線傳送大型檔案。• Android Beam• Samsung S Beam• 市面上各種藍芽音響

Page 8: Nfc tutorial

讀寫模式• 使用 NFC Tag 啟動 NFC 裝置的一些動作,或從海報或者展覽資訊電子標籤上讀取相關資訊。• 跟 QR CODE 比較

Page 9: Nfc tutorial

NFC Reader/Writer modeLive DEMO

Page 10: Nfc tutorial

實作NFC Tag Reader

Page 11: Nfc tutorial

<uses-permission>• 在 AndroidManifest.xml 裡加上下面這段,讓系統允許 app 去控制

NFC 的硬體。• <uses-permission android:name="android.permission.NFC" />

Page 12: Nfc tutorial

<uses-sdk>• 在 AndroidManifest.xml ,因為 api level 10 以上才支援對 NFC Tag的讀寫功能。• <uses-sdk android:minSdkVersion="10" />

Page 13: Nfc tutorial

NFC Tag 支援的資料格式

Page 14: Nfc tutorial

Android has the most support for the NDEF standard • The data stored in the tag can also be written in a variety of formats,

but many of the Android framework APIs are based around a NFC Forumstandard called NDEF (NFC Data Exchange Format).• Android has the most support for the NDEF standard, which is defined

by the NFC Forum.

Page 15: Nfc tutorial

NDEFNDEF 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.

Page 16: Nfc tutorial

Obtaining information from intents• If an activity starts because of an NFC intent, you can obtain

information about the scanned NFC tag from the intent.

• NdefMessage 被封裝在 intent 裡面, activity 就是透過 tag 所傳的intent 被 trigger 起來。

Page 17: Nfc tutorial

The Tag Dispatch System

Page 18: Nfc tutorial

<intent-filter>

Page 19: Nfc tutorial

Layout Design

Page 20: Nfc tutorial

在 onResume 時做動作

Page 21: Nfc tutorial

自訂方法 : getNdefMessages

Page 22: Nfc tutorial

自訂方法 : setNoteBody

Page 23: Nfc tutorial

實作NFC Tag Writer

Page 24: Nfc tutorial

<uses-permission>• 在 AndroidManifest.xml 裡加上下面這段,讓系統允許 app 去控制

NFC 的硬體。• <uses-permission android:name="android.permission.NFC" />

Page 25: Nfc tutorial

<uses-sdk>• 在 AndroidManifest.xml ,因為 api level 10 以上才支援對 NFC Tag的讀寫功能。• <uses-sdk android:minSdkVersion="10" />

Page 26: Nfc tutorial

UI 設計

Page 27: Nfc tutorial

NfcAdapter

Page 28: Nfc tutorial

OnClickListener()

Page 29: Nfc tutorial

enableForegroundDispatch()

Page 30: Nfc tutorial

onNewIntent()

Page 31: Nfc tutorial

NDEFNDEF 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.

Page 32: Nfc tutorial
Page 33: Nfc tutorial
Page 34: Nfc tutorial
Page 35: Nfc tutorial
Page 36: Nfc tutorial

小結• 優缺點