简体   繁体   English

在Android中,如何在没有前台活动的情况下使用NFC操作=

[英]In Android, How can I consume NFC actions without having a foreground activity =

I'm trying to read a nfc tag in the background and then save the read message in a file. 我正在尝试在后台读取nfc标记,然后将读取的消息保存在文件中。 However, the only way i found is having an activity on top. 但是,我发现的唯一方法是在顶部进行活动。 I also tried with a service but the NfcAdapter cannot directly communicate with android services using ACTIONS. 我也尝试使用服务,但是NfcAdapter无法使用ACTIONS与Android服务直接通信。

Only Activities can receive NFC intents. 只有活动可以接收NFC意图。 There is no way for a background task or a service to receive them. 后台任务或服务无法接收它们。 This is an intentional design choice, I think. 我认为这是一个故意的设计选择。 It always gives the user full control, just like with the Android Beam screen that the user has to tap before any data is shared over NFC. 就像在用户通过NFC共享任何数据之前必须轻按的Android Beam屏幕一样,它始终为用户提供完全的控制权。

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

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