首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >阅读信用卡上的NFC消息

阅读信用卡上的NFC消息
EN

Stack Overflow用户
提问于 2021-10-28 13:39:32
回答 1查看 46关注 0票数 0

我希望能够读取不同卡的NFC消息。当我使用我公司的NDEF-MifareClassic-NfcA卡时,一切运行正常。当我尝试使用我的信用卡或Underground-Oyster卡时,即使我看到其他应用程序可以检测到这些卡,也没有检测到任何东西。

这是我在Android Manifest中的内容:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.nfc">
    <uses-permission android:name="android.permission.NFC" />
    <uses-feature
        android:name="android.hardware.nfc"
        android:required="true" />

    <application
        android:allowBackup="false"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.NFC">

        <meta-data
            android:name="com.google.android.actions"
            android:resource="@xml/nfc_tech_filter" />

        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:label="@string/app_name"
            android:theme="@style/Theme.NFC.NoActionBar">

            <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:mimeType="text/plain" />
            </intent-filter>

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

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

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

            <intent-filter>
                <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:scheme="https"
                    android:host="developer.android.com"
                    android:pathPrefix="/index.html" />
            </intent-filter>

        </activity>
    </application>

</manifest>

这是我在Android Manifest中引用的@xml/nfc_tech_filter文件中的内容:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <tech-list>
        <tech>android.nfc.tech.Ndef</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.NdefFormatable</tech>
        <tech>android.nfc.tech.IsoDep</tech>
        <tech>android.nfc.tech.MifareClassic</tech>
        <tech>android.nfc.tech.MifareUltralight</tech>
    </tech-list>
</resources>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-10-29 18:17:49

我找到问题了。我把这个部分放在:

代码语言:javascript
复制
<meta-data
    android:name="com.google.android.actions"
    android:resource="@xml/nfc_tech_filter" />

在错误的地方。它应该与<activity>中的筛选器一起出现。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69755170

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档