enable

fun enable(activity: Activity, callback: NfcAdapter.ReaderCallback, presenceCheckDelayMillis: Long = DEFAULT_PRESENCE_CHECK_DELAY_MILLIS, platformSounds: Boolean = true): NfcUnavailable.Reason?

Turns reader mode on for activity, with callback as the one who hears every discovered tag: pass the NfcChipRead. Call it once for each read, while the read screen is shown, on the main thread.

Return

null when reader mode is on (or will be when activity resumes); otherwise why it is not, the same reasons a read reports through ChipReadEnding.NotStarted: NOT_SUPPORTED when the device has no NFC reader (the platform documents UnsupportedOperationException for that), DISABLED when NFC is off (the platform ignores reader mode then), NOT_PERMITTED when the platform refuses the app (SecurityException), and REQUEST_REFUSED for any other refusal, such as the IllegalStateException the platform throws when the Activity has set another discovery technology. TAG_READING_DISABLED when NFC is on but its option for reading tags is off (known from Android 15, API level 35, on). When it is not null and callback is an NfcChipRead, the read has already ended with ChipReadEnding.NotStarted and this reason, as the Activity-owning start ends it: show why, and do not wait for a document. Calling its cancel() then changes nothing.

Parameters

activity

The read screen.

callback

The read; the platform hands it every tag it finds while activity is resumed.

presenceCheckDelayMillis

How often the platform checks that the tag is still there, in milliseconds.

platformSounds

false to turn the platform's sound off, when your app gives its own feedback; the default leaves it on.