Last active
December 11, 2015 05:48
-
-
Save meco300/4554544 to your computer and use it in GitHub Desktop.
フォアグラウンドにアプリがなくてもNFCを読み込んだときに反応するためには、Intent-filterの追加と、XMLファイルを一つ追加します。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
resフォルダの中にXMLフォルダを作成し、nfc_tech_filter.xmlファイルを作成します。反応するタグの種類を内に書き込みます。