android nfc意图分派问题

wd2eg0qa  于 2022-11-03  发布在  Android
关注(0)|答案(1)|浏览(211)

我试图发挥周围与我的新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);
    }
}

和菜单. 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_技术_过滤器. 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)只会启动名为“收集的新标签”的内置活动,但从不显示选择也不启动我的活动。知道为什么会发生这种情况,感谢任何帮助。

k2arahey

k2arahey1#

Android文档中有一个关于tech-list的错误,我花了很长时间才弄清楚。你必须为每个项目打开一个列表,如下所示,才能使其正常工作:

<?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>

相关问题