2012-05-15 37 views
2

我测试使用的是Nexus S.AIR/Android的NFC标签打开浏览器

我的NFC标签上有,例如样本网址的启用NFC的Android/AIR应用程序“http://www.google.com”。

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

当标签被轻敲时,手机将在浏览器中打开url。

我想知道是否有我在清单中丢失的东西,或者如果链接总是由浏览器处理。我查看了docs,我甚至为特定网址添加了一个计划,但仍然没有运气。

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

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

回答

2

NFC标签上的URL与NFC标签上的纯文本信息不同。他们有不同的消息类型。您的清单列出了纯文本消息的两个意图过滤器(最后一个实际上永远不会触发,TAG_DISCOVERED意图永远不会包含标记中的任何数据)。 匹配您的样本网址尝试,而不是:

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

http://developer.android.com/guide/topics/nfc/nfc.html#ndef-disc见的NDEF_DISCOVEREDhttp://developer.android.com/guide/topics/manifest/data-element.html为的什么可以在一个<data>元素去完整的文档更详细的解释。

+0

非常感谢。 – shackleton

相关问题