Skip to content

Instantly share code, notes, and snippets.

@meco300
Last active December 11, 2015 05:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meco300/4554544 to your computer and use it in GitHub Desktop.
Save meco300/4554544 to your computer and use it in GitHub Desktop.
フォアグラウンドにアプリがなくてもNFCを読み込んだときに反応するためには、Intent-filterの追加と、XMLファイルを一つ追加します。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.nfc_test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10" />
<uses-permission android:name="android.permission.NFC" />
<uses-feature
android:name="android.hardware.nfc"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<!-- ⑤Launchモードの設定。これをしないと何度も同じActivityが発生する -->
<activity
android:name="com.test.nfc_test.MainActivity"
android:label="@string/app_name"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- ▼アプリ立ち上げてなくても反応 -->
<intent-filter >
<action android:name="android.nfc.action.TECH_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data
android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="@xml/nfc_tech_filter" />
<!-- 新規作成したnfc_tech_filter.xml▲ -->
<!-- ▲アプリ立ち上げてなくても反応 -->
</activity>
<!-- ⑤ -->
<activity
android:name="com.test.nfc_test.ResultActivity"
android:label="@string/app_name"
android:launchMode="singleInstance">
</activity>
</application>
</manifest>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<tech-list>
<tech>android.nfc.tech.NfcF</tech>
</tech-list>
<tech-list>
<tech>android.nfc.tech.NfcA</tech>
</tech-list>
</resources>
@meco300
Copy link
Author

meco300 commented Jan 18, 2013

resフォルダの中にXMLフォルダを作成し、nfc_tech_filter.xmlファイルを作成します。反応するタグの種類を内に書き込みます。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment