調査中につき、内容に誤りがあるかもしれません

NFCの種類

FeliCaSONYの独自仕様。処理が速いらしい
MifareType A に基づいた規格
Type Ataspo
Type B住民基本台帳カード、自動車運転免許証、パスポート
Type C

NFCのディスパッチ方式

モード優先順位概要
NDEF_DISCOVERED1
TECH_DISCOVERED2
TAG_DISCOVERED3

NFCを読み込むためのAndroidManifest.xmlの記述

NDEF_DISCOVERED

未調査

TECH_DISCOVERED

ポイント

#codeprettify{{

?xml version="1.0" encoding="utf-8"?>

manifest xmlns:android="http://schemas.android.com/apk/res/android"

	package="xx.xx.xx.xxxxx"
	android:versionCode="1"
	android:versionName="1.0" >

!-- uses-feature、uses-permissonを追加する -->

	<uses-feature
		android:name="android.hardware.nfc"
		android:required="true" />
	<uses-permission android:name="android.permission.NFC" />
	<uses-sdk
		android:minSdkVersion="14"
		android:targetSdkVersion="14" />
	<application
		android:allowBackup="true"
		android:icon="@drawable/ic_launcher"
		android:label="@string/app_name"
		android:theme="@style/AppTheme" >
		<activity
			android:name="xx.xx.xx.xxxx.MainActivity"
			android:label="@string/app_name"
			android:permission="android.permission.NFC" >

!-- intent-filterを追加する -->

			<intent-filter>
				<action android:name="android.nfc.action.TECH_DISCOVERED" />
				<category android:name="android.intent.category.DEFAULT" />
			</intent-filter>

!-- meta-dataを追加する -->

			<meta-data
				android:name="android.nfc.action.TECH_DISCOVERED"
				android:resource="@xml/nfc_filter" />
		</activity>
	</application>

/manifest> }}

TAG_DISCOVERED

ポイント

#codeprettify{{

?xml version="1.0" encoding="utf-8"?>

manifest xmlns:android="http://schemas.android.com/apk/res/android"

	package="jp.project.dev.nfcreader"
	android:versionCode="1"
	android:versionName="1.0" >

!-- uses-feature、uses-permissonを追加する -->

	<uses-feature
		android:name="android.hardware.nfc"
		android:required="true" />
	<uses-permission android:name="android.permission.NFC" />
	<uses-sdk
		android:minSdkVersion="14"
		android:targetSdkVersion="14" />
	<application
		android:allowBackup="true"
		android:icon="@drawable/ic_launcher"
		android:label="@string/app_name"
		android:theme="@style/AppTheme" >
		<activity
			android:name="jp.project.dev.nfcreader.MainActivity"
			android:label="@string/app_name"
			android:permission="android.permission.NFC" >

!-- intent-filterを追加する -->

			<intent-filter>
				<action android:name="android.nfc.action.TAG_DISCOVERED" />
				<category android:name="android.intent.category.DEFAULT" />
			</intent-filter>

!-- meta-dataを追加する -->

			<meta-data
				android:name="android.nfc.action.TAG_DISCOVERED"
				android:resource="@xml/nfc_filter" />
		</activity>
	</application>

/manifest> }}

tech-listの作成

AndroidManifest.xmlのmeta-dataで指定したXMLを作成します。
作成する場所は、/プロジェクト/res/xmlになります。
今回の例だと、/プロジェクト/res/xml/nfc_filter.xmlを作成します。

#codeprettify{{

?xml version="1.0" encoding="utf-8"?>

resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">

   <tech-list>
       <tech>android.nfc.tech.IsoDep</tech>
   </tech-list>
   <tech-list>
   	<tech>android.nfc.tech.MifareClassic</tech>
   </tech-list>
   <tech-list>
   	<tech>android.nfc.tech.MifareUltralight</tech>
   </tech-list>
   <tech-list>
   	<tech>android.nfc.tech.Ndef</tech>
   </tech-list>
   <tech-list>
   	<tech>android.nfc.tech.NdefFormatable</tech>
   </tech-list>
   <tech-list>
   	<tech>android.nfc.tech.NfcA</tech>
   </tech-list>
   <tech-list>
   	<tech>android.nfc.tech.NfcB</tech>
   </tech-list>
   <tech-list>
   	<tech>android.nfc.tech.NfcBarcode</tech>
   </tech-list>
   <tech-list>
   	<tech>android.nfc.tech.NfcF</tech>
   </tech-list>
   <tech-list>
   	<tech>android.nfc.tech.NfcV</tech>
   </tech-list>

/resources> }} 以下のように記述すると、うまく動作しない場合があるようです。
(もしかするとディスパッチする方法によって変わるかも?)

#codeprettify{{

?xml version="1.0" encoding="utf-8"?>

resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">

   <tech-list>
       <tech>android.nfc.tech.IsoDep</tech>
   	<tech>android.nfc.tech.MifareClassic</tech>
   	<tech>android.nfc.tech.MifareUltralight</tech>
   	<tech>android.nfc.tech.Ndef</tech>
   	<tech>android.nfc.tech.NdefFormatable</tech>
   	<tech>android.nfc.tech.NfcA</tech>
   	<tech>android.nfc.tech.NfcB</tech>
   	<tech>android.nfc.tech.NfcBarcode</tech>
   	<tech>android.nfc.tech.NfcF</tech>
   	<tech>android.nfc.tech.NfcV</tech>
   </tech-list>

/resources> }}

intentを受け取る

NFCを読み込むと、intent経由でActivityが呼び出されます。

参考


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2013-04-02 (火) 00:20:22