NFC 意图调度问题

发布于 2024-12-05 16:18:38 字数 1797 浏览 3 评论 0原文

我正在尝试使用我的新 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

原谅我要高飞 2024-12-12 16:18:38

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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文