问题与NFC意图调度意图、问题、NFC

2023-09-05 10:31:44 作者:一瞬间的回眸

我想玩弄我的新的Andr​​oid设备和NFC标签,在那里我有writen一个非常简单的应用程序,以检测NFC标签。但不过我想,我不能让我的设备开始我的活动时,标签被扫描。这里是我有:

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:

最简单的活动:

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

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>

根据资源的nfc_tech_filter.xml / XML:

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>

问题:

每当标签进行扫描,我的设备(的Nexus S 2.3.3)只启动内置的活动称为收集新的标签,但从来没有显示出选择,也开始了我的活动。任何想法,为什么发生这种情况,感谢您的帮助。

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.

推荐答案

有关于高科技名单,我花了相当长的一段弄清楚首先在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:

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