Search code examples
androidnfc

Nfc tag detected/lost listener


I have been working on NFC MifareClassic card. I have read and written data on card. I want to show a notification to user when tag is detected that what I have,

    @Override
    protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    // 1) Parse the intent and get the action that triggered this intent
    String action = intent.getAction();
    if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)) {
        //  3) Get an instance of the TAG from the NfcAdapter

        Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);


        AppController.getInstance().setTag(tagFromIntent);

    }
}

but when tag is move away that is what I need. I want to show user that tag is no longer available. Is there any listener for it?


Solution

  • It is not possible to detect when the tag is no longer available, because the tags don't operate via proximity to the tag reader, they work by reading the tag when passed over the reader.

    You could of course implement your own detection of when the tag goes out of range by polling the tag over a period of time. And if it goes out of range you could trigger your own event by using a delegate.