NFC 意图调度问题
我正在尝试使用我的新 Android 设备和 nfc 标签,我在其中编写了一个非常简单的应用程序来检测 nfc 标签。但无论我如何尝试,在扫描标签时我都无法让我的设备开始我的活动。这是我所拥有的:
最简单的 Activity:
public class NFCIntentDispatch extends Activity{
private TextView mText;
public void onCreate(Bundle savedState) {
super.onCreate(savedState);
setContentView(R.layout.intent_dispatch);
mText = (TextView) findViewById(R.id.text);
}
}
以及
<activity android:name="NFCIntentDispatch">
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED"/>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="@xml/nfc_tech_filter" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
res/xml 下的 menifest.xml nfc_tech_filter.xml:
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<tech-list>
<tech>android.nfc.tech.IsoDep</tech>
<tech>android.nfc.tech.NfcA</tech>
<tech>android.nfc.tech.NfcB</tech>
<tech>android.nfc.tech.NfcF</tech>
<tech>android.nfc.tech.NfcV</tech>
<tech>android.nfc.tech.Ndef</tech>
<tech>android.nfc.tech.NdefFormatable</tech>
<tech>android.nfc.tech.MifareClassic</tech>
<tech>android.nfc.tech.MifareUltralight</tech>
</tech-list>
问题:
每当扫描标签时,我的设备(Nexus S 2.3.3)仅启动名为“收集的新标签”的内置活动,但从不显示选择或启动我的活动。知道为什么会发生这种情况,感谢您的帮助。
I am trying to play around with my new android device and a nfc tag, where I have writen a very simple application to detect nfc tag. but however I tried, I could not get my device to start my activity when the tag is scanned. here is what I have:
the simplest Activity:
public class NFCIntentDispatch extends Activity{
private TextView mText;
public void onCreate(Bundle savedState) {
super.onCreate(savedState);
setContentView(R.layout.intent_dispatch);
mText = (TextView) findViewById(R.id.text);
}
}
and menifest.xml
<activity android:name="NFCIntentDispatch">
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED"/>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="@xml/nfc_tech_filter" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
the nfc_tech_filter.xml under res/xml:
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<tech-list>
<tech>android.nfc.tech.IsoDep</tech>
<tech>android.nfc.tech.NfcA</tech>
<tech>android.nfc.tech.NfcB</tech>
<tech>android.nfc.tech.NfcF</tech>
<tech>android.nfc.tech.NfcV</tech>
<tech>android.nfc.tech.Ndef</tech>
<tech>android.nfc.tech.NdefFormatable</tech>
<tech>android.nfc.tech.MifareClassic</tech>
<tech>android.nfc.tech.MifareUltralight</tech>
</tech-list>
the problem:
whenever the tag is scanned, my device(Nexus S 2.3.3) only launches the build in activity called "new tag collected", but never shows a choose nor start my activity. any idea why this is happening, thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Android 文档中有一个关于技术列表的错误,我花了很长时间才弄清楚。
您必须为每个项目打开一个列表,如下所示才能使其正常工作:
There is an error in the Android documentation regarding the tech-list, which took me quite a while to figure out in the first place.
You'll have to open a list for each item, like this in order to get it working: