监听带有未决意图和意图的 NFC
我有一个应用,其中一个订阅了 ACTION_NDEF_DISCOVERED
的待处理意图,一个订阅了 ACTION_TECH_DISCOVERED
的正常意图。
看起来我需要有后一个意图,以便我的应用程序出现在 NFC 选择操作屏幕中。
但是,根据我的待定意图(根据 API 参考code) 我必须扫描标签两次才能触发 OnNewIntent
。
因此出现了一些怀疑:
- 我真的需要两个意图来捕获应用程序扫描内和应用程序外扫描吗?
- 为什么待处理意图需要两次扫描?是因为我在清单和代码中订阅了它(如示例所示),还是因为我有两个 NFC 意图(尽管处于不同的 NFC 意图级别)?
这里是核心问题:
我如何完成这项工作,以便在应用程序外部我的应用程序出现在 NFC 操作窗口中,而在应用程序内部,OnNewIntent
开火?
I have an app with a pending intent subscribed to ACTION_NDEF_DISCOVERED
and a normal intent subscribed to ACTION_TECH_DISCOVERED
.
It looks like I need to have the latter intent, so that my app will come up in the NFC selection action screen.
However, with my pending intent (which is modeled after the API reference code) I have to scan the tag twice for the OnNewIntent
to fire.
So a few suspicions arise:
- Do I really need two intents to capture both in app scans and out of app scans?
- Why is that the pending intent is requiring two scans? Is it because I’m subscribing with it in the manifest and in code as shown in the sample or because I have two NFC intents (albeit at different NFC intent levels) ?
Here's the core question:
How do I make this work so that, outside of the app my app comes up in the NFC actions window and inside the app only scan is required for OnNewIntent
to fire?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从你的描述来看,你的代码设置基本上没问题。您可能错过了一件事情:当您的应用程序从 NFC 操作窗口(应用程序选择器)启动时,您的应用程序的
Activity
将通过onCreate()
启动,并且您可以使用getIntent()
检索 NFC 意图。仅在enableForegroundDispatch()
(使用PendingIntent
)之后,新的 NFC 意图才会导致调用onNewIntent()
。你可以这样做:
From your description, it looks like your set-up of the code is mostly OK. One thing you may have missed: when your app is started from the NFC actions window (the app chooser), your app's
Activity
will be started withonCreate()
and you have to retrieve the NFC intent withgetIntent()
. Only after theenableForegroundDispatch()
(with thePendingIntent
), new NFC intents will causeonNewIntent()
to be called.You could do it like this: