@@ -60,7 +60,7 @@ open class NfcControlActivity : Activity() {
6060 return
6161 }
6262
63- if (intent == null || NfcAdapter . ACTION_NDEF_DISCOVERED != intent.action ) return
63+ if (intent == null ) return
6464
6565 // Require a physical Tag object. Only the Android NFC subsystem can supply this;
6666 // an explicit intent crafted by another app cannot forge a real Tag instance,
@@ -73,6 +73,13 @@ open class NfcControlActivity : Activity() {
7373 return
7474 }
7575
76+ when (intent.action) {
77+ NfcAdapter .ACTION_NDEF_DISCOVERED -> handleNdefIntent(intent, nfcTag)
78+ NfcAdapter .ACTION_TAG_DISCOVERED -> handleTagIntent(nfcTag)
79+ }
80+ }
81+
82+ private fun handleNdefIntent (intent : Intent , nfcTag : Tag ) {
7683 // getParcelableArrayExtra(String) deprecated in API 33; type-safe overload requires API 33+, minSdk=26
7784 @Suppress(" DEPRECATION" )
7885 val rawMsgs = intent.getParcelableArrayExtra(NfcAdapter .EXTRA_NDEF_MESSAGES ) ? : return
@@ -90,11 +97,23 @@ open class NfcControlActivity : Activity() {
9097 }
9198
9299 val tagUid = NfcTokenSupport .tagUidHex(nfcTag.id) ? : return
93- aapsLogger.debug(LTag .NFC , " NFC tag scanned, UID: $tagUid " )
100+ executeByUid(tagUid, showErrorToast = true )
101+ }
94102
103+ private fun handleTagIntent (nfcTag : Tag ) {
104+ val tagUid = NfcTokenSupport .tagUidHex(nfcTag.id) ? : return
105+ aapsLogger.debug(LTag .NFC , " TAG_DISCOVERED fallback, UID: $tagUid " )
106+ // Silently ignore tags not registered in My Tags — TAG_DISCOVERED fires for all tags
107+ // (credit cards, transit cards, etc.) and an error toast for every unknown card is
108+ // intrusive. Only execute if the UID is explicitly registered.
109+ executeByUid(tagUid, showErrorToast = false )
110+ }
111+
112+ private fun executeByUid (tagUid : String , showErrorToast : Boolean ) {
113+ aapsLogger.debug(LTag .NFC , " NFC tag scanned, UID: $tagUid " )
95114 when (val prep = nfcPlugin.prepareExecution(tagUid)) {
96115 is NfcPrepareResult .Error -> {
97- showToast(prep.message)
116+ if (showErrorToast) showToast(prep.message)
98117 return
99118 }
100119 is NfcPrepareResult .Ready -> {
0 commit comments