title: Android: How to read NFC tag with current app
body: <p>I'm writing an app which needs to read NFC tags. Rather than the act of reading the tag opening up a new app via intent filters I would like my currently open app to simply read a nearby tag.</p>
  
  <p>I have tried to use enableForegroundDispatch() but with no luck. Whenever an NFC tag is present my device simply opens up the standard "Tags" app instead.</p>
  
  <p>The code I have so far is:</p>
  
  <pre><code>final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass());
  intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
  final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0);
  IntentFilter[] filters = new IntentFilter[1];
  String[][] techList = new String[][]{};
  filters[0] = new IntentFilter();
  filters[0].addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
  filters[0].addCategory(Intent.CATEGORY_DEFAULT);
  try {
      filters[0].addDataType(MIME_TEXT_PLAIN);
  } catch (MalformedMimeTypeException e) {
      throw new RuntimeException("Check your mime type.");
  }
  adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList);
  </code></pre>
  
  <p>(Which is basically copied from a tutorial that I found).</p>
  
  <p>Does anyone know if this is the right way of going about this?
  How can I prevent the standard "Tags" app from opening up instead of my own app receiving the NDEF_DISCOVERED intent.</p>
  
  <p>Thanks</p>