gpt4 book ai didi

java - 我的 NFC 扫描应用程序仅在 NFC 类型 2 时启动

转载 作者:行者123 更新时间:2023-12-01 18:27:38 25 4
gpt4 key购买 nike

我制作了一个可以读取 NFC 标签的 NFC 应用程序。效果很好。 (所有类型)

但从昨天开始,我尝试在我的设备上维护 NFC 标签后自动启动我的应用程序。

所以我更新了我的 list :

        <activity android:name=".MainActivity" android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>


<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED"/>
</intent-filter>

<meta-data android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="@xml/nfc_tech_filter" />
</activity>

然后,这是我的 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>
</resources>

令人惊讶的是,它仅在我将 NFC Type 2 靠近我的设备时才起作用。我尝试使用我的公寓 key (Mifare Classic) 和银行卡 (IsoDep),但它没有启动我的应用程序...我指定它在我的应用程序已启动时起作用。

有什么想法吗?

编辑:

这是我现在的 list :


<activity android:name=".MainActivity" android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED" android:resource="@xml/nfc_tech_filter" />
</activity>

现在,当我通过银行卡时,它会打开应用程序,但不会显示任何结果。

Parcelable[] rawMessages =
intent.getParcelableArrayExtra(NfcAdapter.EXTRA_TAG);

rawMessages 变量之后为 NULL。如果我把 NfcAdapter.EXTRA_NDEF_MESSAGES 也一样

最佳答案

ACTION_TAG_DISCOVERED:

This intent is started if no activities handle the ACTION_NDEF_DISCOVERED or ACTION_TECH_DISCOVERED intents.

https://developer.android.com/guide/topics/connectivity/nfc/nfc

当没有其他人捕获此 Intent 时,您获得了此 Intent,因此您的设置有问题。

您可以明确捕获它,例如:

<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED"/>
</intent-filter>

关于java - 我的 NFC 扫描应用程序仅在 NFC 类型 2 时启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60208659/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com