美文网首页生活小惊喜
【转】NFC 注册之AndroidManifest方式

【转】NFC 注册之AndroidManifest方式

作者: justin_pan | 来源:发表于2015-05-25 11:44 被阅读319次

转:http://blog.csdn.net/johnnycode/article/details/24807833
NFC注册方式分为两种,第一种在 AndroidManifest.xml 中进行注册,第二在代码中动态注册。
本次介绍 AndroidManifest 中注册方式。

1、添加NFC权限

<uses-permission android:name="android.permission.NFC" />

2、在Activity中添加事件

[html] view plaincopy

在CODE上查看代码片在CODE上查看代码片 派生到我的代码片派生到我的代码片

<activity
android:name=".MainActivity"
android:configChanges="keyboardHidden|orientation"
android:launchMode="singleTask"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TAG_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" />
</activity>

3、创建 nfc_tech_filter.xml 文件内容,xml保存路径在 res/xml/ 下
[html] view plaincopy

在CODE上查看代码片在CODE上查看代码片 派生到我的代码片派生到我的代码片

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2" >
<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.NfcA</tech>
</tech-list>
<tech-list>
<tech>android.nfc.tech.NfcF</tech>
</tech-list>
<tech-list>
<tech>android.nfc.tech.Ndef</tech>
</tech-list>
<tech-list>
<tech>android.nfc.tech.NfcV</tech>
</tech-list>
<tech-list>
<tech>android.nfc.tech.NfcB</tech>
</tech-list>
<tech-list>
<tech>android.nfc.tech.NdefFormatable</tech>
</tech-list>
<tech-list>
<tech>android.nfc.tech.IsoDep</tech>
</tech-list>
</resources>

OK,搞定!注意 nfc_tech_filter.xml 中内容不要格式化否则无法进行NFC标签匹配。

相关文章

网友评论

    本文标题:【转】NFC 注册之AndroidManifest方式

    本文链接:https://www.haomeiwen.com/subject/bkrrqttx.html