Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
197 views
in Technique[技术] by (71.8m points)

android - Reading a tag from a specific activity

I just finished my android app that have 1 activity, wherein it displays the data on the nfc tag, my problem is that whenever I tap nfc tag, the app opens/launch even if it is not open or running in the background. How can I prevent this from happening?

I want my app to react when it is open, thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you don't want your activity to automatically start upon scanning a tag, simply don't register NFC related intent filters in your app's manifest.

But what if...

  1. ... you did not register any NFC related intent filters in the manifest but instead stored an Android Application Record (AAR) on the NFC tag. In this case your only option is to not use AARs.

  2. ... you now can't display the tag's data in your activity, because you do not receive any intent upon scanning an NFC tag. In this case, you should have registered for the NFC foreground dispatch system instead of registering an NFC intent filter in your app's manifest.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...