How to Read NFC Tag?

前端 未结 4 877
花落未央
花落未央 2020-12-06 23:13

Hi I am trying to read from NFC Tag. But I am getting an exception.

I have put this condition to detect the tag?

if(NfcAdapter.ACTION_TAG_DISCOVERED          


        
4条回答
  •  一生所求
    2020-12-07 00:04

    To answer you question about the code -

    That will always be true - NfcAdapter.ACTION_TAG_DISCOVERED is a constant value - you need to use:

    getIntent().getAction().equals(NfcAdapter.ACTION_TAG_DISCOVERED) 
    

    to compare it.

    But, that probably has nothing to do with your exception -

    1. did you include the NFC permission in your android manifest?
    2. are you sure your phone supports NFC, only two or three support it at this time.
    3. we'd need the stack trace from your logs to know what caused the exception

提交回复
热议问题