无法过滤网址NDEF Android Intent

时间:2018-03-05 16:24:22

标签: android android-intent nfc intentfilter ndef

SE上有很多关于如何做到这一点的例子,但我似乎无法让它发挥作用。我想要做的是扫描带有dev.example.com的标签,启动我的应用程序,如果已安装,或者如果没有安装,只需转到标签中的URL。无论应用程序是否正在运行,都会发生这种情况。

在清单中:

<activity android:name=".MainActivity">
 <intent-filter  android:label="@string/app_name">
    <action android:name="android.nfc.action.NDEF_DISCOVERED" />
    <category android:name="android.intent.category.DEFAULT" />
    <data
      android:host="dev.example.com"
      android:scheme="https" />
 </intent-filter>

我有一个带有https://dev.example.com的NFC标签写入第一个NDEF记录。

无论我做什么,如果我用S7扫描它,它会弹出

  

NFC请求

     

系统会要求您打开网址标记   (https://dev.example.com

     

[]再也不要问我关于nfc的事了

     

取消确定

(我从不点击&#34;不要再问我了#34;) 单击“确定”将启动默认浏览器。

如果我更改清单以过滤明文NDEF ..

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

我写了一个文本NDEF记录,我的应用确实启动了。

那为什么网址不起作用?

我也尝试过添加

android:pathPrefix="/app"

到url intent并将https://dev.example.com/app写入标记。我的应用程序仍然没有拦截任何URL NDEF记录。

我也有

protected void onNewIntent(Intent intent) {}

在我的主要活动中,但它永远不会被调用,即使文本NDEF启动应用程序。但一次只有一个问题..

我真的没有其他手机可以试用。我尝试了另一个S7,它只是启动了URL,无论是否安装了应用程序。 (他可能检查了#34;不要再问了#34;)

感谢。

编辑:为了完整性,继承人NDEF。 enter image description here

1 个答案:

答案 0 :(得分:0)

为了避免弹出窗口,应将pathPrefix属性添加到URI意图:

<data
      android:host="dev.example.com"
      android:scheme="https" 
      android:pathPrefix="/" />