gpt4 book ai didi

android - 如何将 NFC 标签上的 AAR 重定向到新的应用程序 ID?

转载 作者:行者123 更新时间:2023-11-30 00:03:33 25 4
gpt4 key购买 nike

我有一个带有两条记录的 NDEF NFC 标签:

  • 第一个包含我的网站 URL。
  • 第二个是带有我旧应用程序 ID 的 AAR。

到目前为止,旧应用程序在发现 NFC 标签时正常启动。

但我想创建一个新的应用程序来处理这些 NFC 标签,而不是旧的。

我在 list 中添加了:

<android:name=".splash.SplashActivity"
android:screenOrientation="portrait"
android:stateNotNeeded="true"
android:theme="@style/SplashTheme">

<meta-data android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="@xml/nfc_tech_filter" />

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

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

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

我的手机上安装了新应用程序,但当我轻触 NFC 标签时,它会打开 Play 商店并将我重定向到旧应用程序。

是否可以创建一个 NFC 过滤器,当发现包含其他应用程序 ID 的标签时将被触发?

最佳答案

不,不可能启动带有该标签的新应用程序。 Android 应用程序记录 (AAR) 的整个想法就是防止这种情况发生(请参阅 NFC Basics):

[... an AAR] provides a stronger certainty that your application is started when an NFC tag is scanned. [...] AARs are useful if you want to prevent other applications from filtering for the same intent and potentially handling specific tags that you have deployed.

因此,如果您想使用 NFC 标签启动您的应用,唯一的选择是替换标签上的数据(或整个标签,以防写入锁定)。

但是,如果您只想在您的(新)应用程序已经在前台打开时读取标签,您可以使用前台调度系统或阅读器模式来覆盖该行为并强制 Android 将标签发现事件调度到你的(新)应用程序。参见 Using the Foreground Dispatch System .

关于android - 如何将 NFC 标签上的 AAR 重定向到新的应用程序 ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49446395/

25 4 0