NFC - 如何使用 NDEF_DISCOVERED 启动应用程序

发布于 2024-12-27 09:59:17 字数 908 浏览 3 评论 0原文

我正在编写一个应用程序,该应用程序应该检测 nfc 标签并自动启动。 我已经通过使用 TECH_DISCOVERED + 过滤器成功做到了这一点,但我认为更好的方法是使用 NDEF_DISCOVERED。 我已将意图过滤器添加到我的清单中,但它不起作用。 这是我的 TECH_DISCOVERED 清单代码,有效:

    <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" />

当我想尝试 NDEF_DISCOVERED 时,我尝试:

                <intent-filter>    
                <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="text/plain" />

对于标签,我使用“Mifare classic 1k”标签,该标签使用市场上的 NFC TagInfo 应用程序编写为“智能海报”。

我做错了什么? 或者,还有什么方法可以启动我的应用程序而不显示活动选择对话框?

谢谢, 埃兰。

I am writing an application that is supposed to detect nfc tag and automatically be launched.
I have succeeded in doing so by using TECH_DISCOVERED + filters but I think the better way to do it is by using NDEF_DISCOVERED.
I have added the intent-filter to my manifest but it doesn't work.
This is my manifest code for the TECH_DISCOVERED, that works:

    <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" />

when I want to try the NDEF_DISCOVERED i try:

                <intent-filter>    
                <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="text/plain" />

for the tags, I use 'Mifare classic 1k' tags that was written as 'Smart Poster' using NFC TagInfo app from the market.

What am I doing wrong?
or, what is another way to make my app be launched and not show the activity selection dialog?

Thanks,
Eran.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

浪推晚风 2025-01-03 09:59:18

您正在过滤文本/纯文本,而不是智能海报的 URI。 Android 将智能海报转换为 URI,然后您必须过滤该 URI。如果您检查已启动的 Intent,则可以在 logcat 中看到 URI。对于像 http://example.com/file 这样的 URI,请执行以下操作:

<intent-filter>
    <action android:name="android.nfc.action.NDEF_DISCOVERED" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="http"
            android:host="example.com"
            android:pathPrefix="/file" />
</intent-filter>

请参阅 NFC 开发指南有关如何解析 NDEF 消息的更多信息。请阅读整个文档以充分了解如何过滤正确的意图:http:// /developer.android.com/guide/topics/nfc/nfc.html

You are filtering for text/plain and not the URI of the smart poster. Android converts smart posters to URIs, then you have to filter for that URI. You can see the URI in logcat if you check for the intent that is started. For a URI like http://example.com/file, do something like this:

<intent-filter>
    <action android:name="android.nfc.action.NDEF_DISCOVERED" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="http"
            android:host="example.com"
            android:pathPrefix="/file" />
</intent-filter>

See the NFC dev guide for more information on how to parse NDEF messages. Please read the entire document to fully understand how to filter for the right intent: http://developer.android.com/guide/topics/nfc/nfc.html

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