【问题标题】:intent-filter + nfc.addMimeTypeListener re-opens the app again and againintent-filter + nfc.addMimeTypeListener 一次又一次地重新打开应用程序
【发布时间】:2017-06-09 11:12:16
【问题描述】:

我正在使用phonegap-nfc 对 NFC 标签执行所有读/写操作。与 nfc 标签的交互仅在应用的少数页面中启用。

现在我正在尝试添加新功能,即点击 NFC 标签启动我的应用程序(当应用程序未运行时)并对标签执行读取操作。正在启动应用程序。

我在AndroidManifest.xml中添加了intent-filter,如下:

<intent-filter>
    <action android:name="android.nfc.action.NDEF_DISCOVERED" />
    <data android:host="ext" android:pathPrefix="/<my-urn>" android:scheme="vnd.android.nfc" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

并添加nfc.addMimeTypeListener如下:

nfc.addMimeTypeListener('text/any', function () {
  // route to particular page
}, function () {
  console.log('success!');
}, function () {
  console.log('Failed!');
});

我在添加 nfc.addMimeTypeListener 时遇到问题,如果我只添加 Intent-filter(没有 nfc.addMimeTypeListener),它会启动应用程序,当我点击 NFC 标签,要么它什么都不做,要么它根据我所在的页面执行必要的 nfc 操作——这是正确的行为。但是,当我在意图过滤器中添加 nfc.addMimeTypeListener 时,如果我在应用程序已经打开时点击 NFC,它会一次又一次地重新打开应用程序,而不是执行必要的 nfc 操作。不明白我做错了什么!

如有任何帮助,我们将不胜感激!

【问题讨论】:

    标签: android cordova phonegap-plugins nfc


    【解决方案1】:

    您可以尝试删除监听器并在清单本身中添加 mimeType,例如 &lt;data android:mimeType="text/plain" /&gt;

    【讨论】:

      猜你喜欢
      • 2018-10-29
      • 2018-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 2016-09-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多