简体   繁体   English

在 Android 委托之前拦截 Intent (NFC)

[英]Intercept Intent before Android delegates it (NFC)

I have an App that reads NFC Tags.我有一个可以读取 NFC 标签的应用程序。 This works fine so far - when the NfcAdapter.ACTION_TAG_DISCOVERED Intent is fired my Activity1 gets started.到目前为止,这工作正常 - 当 NfcAdapter.ACTION_TAG_DISCOVERED Intent 被触发时,我的 Activity1 开始启动。

Now I have the situation that I have an Activity2 which should read the NFC tag if the Activity2 is on foreground.现在我的情况是我有一个 Activity2,如果 Activity2 在前台,它应该读取 NFC 标签。 So I want the Activity2 to listen to the NFC intent and intercept the intent, so that Activity1 doesn't get started - Activity2 already processed the intent.所以我希望 Activity2 侦听 NFC 意图并拦截该意图,这样 Activity1 就不会启动 - Activity2 已经处理了该意图。

Currently Activity1 has the NFC intent assigned in the Android Manifest and therefore always receives all NFC off the app.当前 Activity1 具有在 Android Manifest 中分配的 NFC Intent,因此始终从应用程序接收所有 NFC。

Background: I have an app that reads NFC Cards from out customers and starts the Customer Details activity.背景:我有一个应用程序可以从客户那里读取 NFC 卡并启动客户详细信息活动。 Now I want to have Admin-Cards that should be used as login if privileged function requested.现在我想拥有管理员卡,如果请求特权功能,应该将其用作登录名。 So I would start a "login-NFC-listener" to let the Admin authenticate via Admin-Card.因此,我将启动一个“登录 NFC 侦听器”,让管理员通过 Admin-Card 进行身份验证。 The currenty situation would start the Customer Details activity instead of my login processing every time.当前情况将启动客户详细信息活动,而不是每次都进行登录处理。

Thank you very much!非常感谢! :) :)

It's more obvious than i thought: http://developer.android.com/guide/topics/connectivity/nfc/advanced-nfc.html#foreground-dispatch这比我想象的更明显: http : //developer.android.com/guide/topics/connectivity/nfc/advanced-nfc.html#foreground-dispatch

I think this will be the solution.我认为这将是解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM