androidnfcandroid-pendingintentandroid-intent-chooser

How to avoid detection of NFC tag in android?


I am making an app with NFC. I want the detection is disabled or drops(no vibration, no sound, no app chooser dialog, no detection notification) in some activities or fragments.

Is that possible?

Only I did is using SingleTop in manifest and to the Intent like this:

In Manifests.xml

    <activity
        android:name=".ui.MainActivity"
        android:launchMode="singleTask"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.nfc.action.NDEF_DISCOVERED" />

            <category android:name="android.intent.category.DEFAULT" />

            <data
                android:host="example.com"
                android:scheme="http"/>
        </intent-filter>
    </activity>

in the MainActivity

val intent = Intent(this, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
pendingIntent = PendingIntent.getActivity(this, 0, intent, 0)

Solution

  • This was because default wallet. Some devices can Choose NFC reader in the NFC setting. You need to turn it off. I never tried the solution that you detect notification and close it. There is NotificationListenerService. You gotta look into it if you want to disable all the notifications.