【问题标题】:AIR/Android NFC tags are opening the BrowserAIR/Android NFC 标签正在打开浏览器
【发布时间】:2012-05-15 20:41:21
【问题描述】:

我正在使用 Nexus S 测试支持 NFC 的 Android/AIR 应用程序。

我的 NFC 标签上有一个示例 url,例如“http://www.google.com”。

我想捕获标签上的 url(或任何文本)以在应用程序中使用。

点击标签时,手机会在浏览器中打开网址。

我想知道我的清单中是否缺少某些内容,或者链接是否始终由浏览器处理。我查看了docs,甚至为特定的 URL 添加了一个方案,但仍然没有运气。

我的清单如下。感谢您的任何意见。

<manifest android:installLocation="auto">
    <uses-permission android:name="android.permission.NFC"/>
    <uses-permission android:name="android.permission.INTERNET"/>

    <uses-feature android:name="android.hardware.nfc" android:required="true"/>

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

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

            <intent-filter> 
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

【问题讨论】:

    标签: android flash air nfc


    【解决方案1】:

    NFC 标签上的 URL 与 NFC 标签上的纯文本消息不同。它们有不同的消息类型。您的清单列出了纯文本消息的 2 个意图过滤器(最后一个永远不会被实际触发, TAG_DISCOVERED 意图永远不会包含来自标签的任何数据)。 为了匹配您的示例 URL,请尝试:

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

    有关NDEF_DISCOVERED 的更详细说明,另请参阅http://developer.android.com/guide/topics/nfc/nfc.html#ndef-disc,有关&lt;data&gt; 元素的完整文档,请参阅http://developer.android.com/guide/topics/manifest/data-element.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-31
      • 1970-01-01
      • 2018-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-16
      相关资源
      最近更新 更多