android - 无法过滤 URL NDEF Android Intent

标签 android android-intent nfc intentfilter ndef

SE 上有大量关于如何执行此操作的示例,但我似乎无法让它工作。我想要做的是当扫描带有 dev.example.com 的标签时,我的应用程序已启动,如果已安装,或者如果未安装,只需转到标签中的 URL。无论应用程序是否正在运行,这都应该发生。

在 list 中:

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

You are being requested to open a web address tag (https://dev.example.com)

[] Dont ask me about nfc again

cancel ok

(我从不点击“不要再问我”) 单击“确定”启动默认浏览器。

如果我更改 list 以过滤纯文本 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 记录,我的应用确实启动了。

为什么 URL 不起作用?

我也试过添加

android:pathPrefix="/app"

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

我还有一个

protected void onNewIntent(Intent intent) {}

在我的主要 Activity 中,但它从未被调用,即使文本 NDEF 启动应用程序也是如此。但一次一个问题..

我真的没有任何其他手机可以试用。我在另一台 S7 上试过,它只是启动了 URL,无论是否安装了该应用程序。 (他可能勾选了“不要再问”)

谢谢。

编辑:为了完整起见,这里是 NDEF。 enter image description here

最佳答案

为了避免弹出窗口,您应该将 pathPrefix 属性添加到 URI Intent 中:

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

关于android - 无法过滤 URL NDEF Android Intent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49115009/

相关文章:

android - 广播接收器 onReceive() 从未调用过

java - Android - 写入 ISO15693 标签

javascript - Cordova/Touch onclick 事件问题

java - Android单元测试: Mock context that also returns a looper

android - MissingPluginException(MissingPluginException(在 channel plugins.flutter.io/google_maps_53 上找不到方法 camera#animate 的实现))

android - 即使我发送了一个 Intent ,OnActivityResult 也会在 Intent 通过时得到 null

android - 在 Android 应用程序中使用 Intent 来显示另一个 Activity

android - NFC 贴纸/标签编码

android - 用于具有默认 NFC 的手机和具有启用 NFC 的 micro SD 卡的手机的代码有什么不同吗?

java - Android- 未找到 R.java 文件