Search code examples
androidprogress-barnfc

Android indicate NFC tag is being scanned realtime


I have been looking for a way to indicate that my app is currently reading a tag. To date I have only been able to get all data at once.

Current scenario: My app opens, I hold a tag to the back of the app and this triggers my ReaderCallback (See snippet)

public class NFCHandler extends Activity implements NfcAdapter.ReaderCallback {
    @Override
    public void onTagDiscovered(Tag tag) {
        StringBuilder build = new StringBuilder();
        for(byte b : tag.getId()){
            build.append(Byte.toString(b) + ".");
        }
        String ID = build.toString();
        ID = ID.substring(0,ID.length() - 1);
        Log.d("DSM","ID Loaded: " + ID);
    }
}

What I wanted to do is: show the user that the NFC tag is in the correct place, by displaying a circulair indeterminate progressbar. I have all aspects of the progressbar in place, I just need a way to trigger it. I know this is possible because some apps already do this, but all these are closed-source, sadly.

I have also dug around android.nfc.tech.* android.nfc.* but yielded no information

This is what I want to achieve: Indicator

I am open to suggestions! Thanks in advance.


Solution

  • I found the solution myself, by accident.

    Use:

    void enableReaderMode (Activity activity, 
                    NfcAdapter.ReaderCallback callback, 
                    int flags, 
                    Bundle extras)
    

    And specify FLAG_READER_SKIP_NDEF_CHECK and FLAG_READER_NFC_A as flags.

    Source here