title: How to erase NFC tag data in android?
body: <p>I'm facing problem when I try to erase data in NFC tag. I'm using MifareUltralight type NFC tag. Please some one help me to find solution. Here is my code. I got this code from <a href="https://stackoverflow.com/questions/13970931/how-to-format-an-nfc-tag-in-ndef-format">here</a></p>
  
  <pre><code>if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())) {
      mytag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
  }
  
  NdefFormatable formatable = NdefFormatable.get(mytag);
  
  if (formatable != null) { // Here I'm getting formatable null
      try {
          formatable.connect();
  
          try {
              formatable.format(methodGetMsg());
          } catch (Exception e) {
              // let the user know the tag refused to format
          }
      } catch (Exception e) {
          // let the user know the tag refused to connect
      } finally {
          try {
              formatable.close();
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  } else {
      // let the user know the tag cannot be formatted
  }
  </code></pre>