Upgrade to Pro — share decks privately, control downloads, hide ads and more …

NFC基礎の基礎

 NFC基礎の基礎

Takahiro Shimokawa

March 17, 2012
Tweet

More Decks by Takahiro Shimokawa

Other Decks in Programming

Transcript

  1. NFCͬͯԿʁ Α͘ฉ͘RFID (radio frequency identifier) ͱͷؔ܎ ࣗಈೝٕࣝज़ͱσʔλऩूٕज़ ͷඪ४Խ RFID ໨తɿ෺ͷ؅ཧ

    ྫɿίΠϯͷத ɹɹճసण࢘ͷࡼ ɹɹຊͷแ૷ͷཪ Χʔυ͓Αͼݸਓࣝผʹؔ͢Δ ٕज़ͷඪ४Խ ඇ઀৮ICΧʔυ ໨తɿਓͷ؅ཧ ྫɿަ௨ܥ ɹɹɹిࢠϚωʔɹ 12೥3݄17೔౔༵೔
  2. NFCͬͯԿʁ ඇ઀৮ICΧʔυͷن֨ NFCIP-2 ( ISO/IEC 21481 ) NFCIP-1 ( ISO/IEC

    18092 ) ISO/IEC 14443 Type B ISO/IEC 18092 Type A ( MIFARE ) ISO/IEC 18092 Type F ( FeliCa ) ISO/IEC 15693 = ISO/IEC 18000-3 Model 1 RFID 12೥3݄17೔౔༵೔
  3. ਎ۙʹ͋Δʁ NFC ( IC ) Χʔυ PASMO, Suica, ICOCA, TOICA,

    ICa, IruCa, RapiCa, passca, Hareca, LuLuCa, monoca, nimoca, Kitaca, SAPICA, SUGOCA, Ecomyca, manaca, Ͱ͔͢, ͳͲ... 12೥3݄17೔౔༵೔
  4. ਎ۙʹ͋Δʁ NFC ( IC ) Χʔυ WAON, nanaco, Edy ໔ڐূ

    λεϙ ॅຽجຊ୆ாΧʔυ 12೥3݄17೔౔༵೔
  5. NFCDemo TagಡΈऔΓॲཧ 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. Android DevelopersΑΓ 12೥3݄17೔౔༵೔
  6. NFCDemo TagಡΈऔΓॲཧ λά σΟεύον γεςϜ ௨ৗ Android ౥ࡌσόΠε͸ɺNFC ͕σόΠεͷઃఆϝχϡʔͰແޮʹͳ͍ͬͯͳ͍ݶΓ͸ɺը໘͕ϩοΫղআ͞Εͨ࣌ʹɺNFC λ

    άΛݟ͚ͭΑ͏ͱ͠·͢ɻAndroid ౥ࡌσόΠε͕ NFC λάΛൃݟ͢ΔͱɺͲͷΞϓϦέʔγϣϯΛ࢖༻͢Δͷ͔ΛϢʔβʹਘͶΔ ͜ͱͳ͘ɺ΋ͬͱ΋ద੾ͳΞΫςΟϏςΟʹͦͷΠϯςϯτΛϋϯυϧͤ͞Δ͜ͱ͕σόΠεʹظ଴͞ΕΔಈ࡞Ͱ͢ɻσόΠε͸ NFC λάΛͱͯ΋୹͍ڑ཭ͰεΩϟϯ͢Δ͜ͱ͔ΒɺϢʔβ͕खಈͰΞΫςΟϏςΟΛબ୒͢ΔͱɺσόΠε͕λά͔Β཭Εͯ͠·͍ɺ઀ ଓ͕੾Εͯ͠·͏ͱ͍ͬͨ͜ͱʹͳΓ͔Ͷ·ͤΜɻ։ൃऀ͸ɺΞΫςΟϏςΟͷબ୒μΠΞϩά͕දࣔ͞Εͳ͍Α͏ʹ͢ΔͨΊʹ΋ɺ ΞΫςΟϏςΟ͕έΞ͢Δ NFC λάΛϋϯυϧ͢Δ͚ͩʹ͢ΔΑ͏ʹઃܭ͢΂͖Ͱ͢ɻ ͜ͷ໨తΛՌͨͨ͢ΊʹɺεΩϟϯ͞Εͨ NFC λάͷղੳɺλάͷύʔε͓ΑͼɺεΩϟϯ͞ΕͨσʔλΛظ଴͢ΔΞϓϦέʔγϣ ϯ΁ͷݕࡧͷࢼΈ͕ Android ʹΑΓఏڙ͞Ε͍ͯ·͢ɻ͜Ε͸ҎԼͷΑ͏ʹ࣮ͯ͠ݱ͞Ε·͢ɻ 1. NFC λάͷύʔεͱλάʹ͋Δσʔλ ϖΠϩʔυΛࣝผ͢Δ MIME λΠϓ΍ URI Λղಡ͠·͢ɻ 2. MIME λΠϓ΍ URI ͱϖΠϩʔυΛΠϯςϯτʹΧϓηϧԽ͠·͢ɻ͜ΕΒͷ࠷ॳͷ 2 ͭͷεςοϓʹ͍ͭͯ͸ NFC λάͷ MIME λΠϓͱ URI ΁ͷϚοϐϯάํࣜ Ͱઆ໌͍ͯ͠·͢ɻ 3. ΠϯςϯτΛجຊͱͯ͠ΞΫςΟϏςΟΛ։࢝͠·͢ɻ͜Εʹ͍ͭͯ͸ NFC λάͷ ΞϓϦέʔγϣϯ΁ͷσΟεύονํࣜ Ͱ આ໌͍ͯ͠·͢ɻ ιϑτ΢ΣΞٕज़υΩϡϝϯτΛউखʹ຋༁ ΑΓ 12೥3݄17೔౔༵೔
  7. NFCDemo “TagView.java” @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.tag_viewer);

    mTagContent = (LinearLayout) findViewById(R.id.list); mTitle = (TextView) findViewById(R.id.title); resolveIntent(getIntent()); } 12೥3݄17೔౔༵೔
  8. NFCDemo “TagViewer.java” String action = intent.getAction(); if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)) { Parcelable[]

    rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); NdefMessage[] msgs; if (rawMsgs != null) { msgs = new NdefMessage[rawMsgs.length]; for (int i = 0; i < rawMsgs.length; i++) { msgs[i] = (NdefMessage) rawMsgs[i]; } ... 12೥3݄17೔౔༵೔