我正在尝试使用我的新Android设备和nfc标签,我写了一个非常简单的应用来检测nfc标签。但是我尝试了,扫描标签时,我无法让我的设备启动我的活动。这就是我所拥有的:
最简单的活动:
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);
}
}
和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>
res / 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)仅启动名为“收集新标签”的内置活动,但从不显示选择或启动我的活动。知道为什么会这样,感谢您的帮助。
答案 0 :(得分:4)
关于技术列表的Android文档中有一个错误,我花了很长时间才弄明白。 您必须为每个项目打开一个列表,如下所示,以使其正常工作:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<tech-list>
<tech>android.nfc.tech.IsoDep</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.NfcF</tech>
</tech-list>
<tech-list>
<tech>android.nfc.tech.NfcV</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.MifareClassic</tech>
</tech-list>
<tech-list>
<tech>android.nfc.tech.MifareUltralight</tech>
</tech-list>
</resources>