title: Start the NFC tag only from my specific application
body: <p>I am just completed the NFC based application. In this I am simply scanning the NFC tag and fetching the serial number of the NFC.</p>
  
  <p>But When NFC tag comes near across the device, then it show all the application list which can scan the NFC tag where there I can set by doing "Always" or "default" but I want this do somehow programmatically.</p>
  
  <p>I am looking for this because it seems to bug in some devices that not working as it seems.</p>
  
  <p>Bug in the devices : I have two devices that is not showing even "Always" or "default as action" in the dialog box when NFC tag come near across the device.</p>
  
  <p>See the screenshot :</p>
  
  <p><img src="https://i.stack.imgur.com/LfMfu.jpg" alt="Screenshot"></p>
  
  <pre><code>&lt;activity
      android:name="net.livepatrols.thepartnerSA.NFCActivity"
      android:theme="@android:style/Theme.NoDisplay" &gt;
      &lt;intent-filter&gt;
          &lt;action android:name="android.nfc.action.TECH_DISCOVERED" /&gt;
      &lt;/intent-filter&gt;
  
      &lt;meta-data
          android:name="android.nfc.action.TECH_DISCOVERED"
          android:resource="@xml/nfc_tech_filter" /&gt;
  
      &lt;intent-filter&gt;
          &lt;action android:name="android.nfc.action.TAG_DISCOVERED" /&gt;
  
          &lt;category android:name="android.intent.category.DEFAULT" /&gt;
      &lt;/intent-filter&gt;
  &lt;/activity&gt;
  </code></pre>
  
  <p>NFCActivity.java</p>
  
  <pre><code>public class NFCActivity extends Activity {
  
      private NfcAdapter mNFCAdapter;
      private PendingIntent mNfcPendingIntent;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_nfc);
  
          // Create the OpenSqliteHelper object. It always best to create only
          // once instance of this OpenSqliteHelper
          DatabaseManager.init(this);
  
          mNFCAdapter = NfcAdapter.getDefaultAdapter(this);
  
          if (mNFCAdapter == null) {
              // Device does not support NFC
              Toast.makeText(this,
                      getString(R.string.device_does_not_support_nfc),
                      Toast.LENGTH_LONG).show();
          } else {
              if (!mNFCAdapter.isEnabled()) {
                  // NFC is disabled
                  Toast.makeText(this, getString(R.string.enable_nfc),
                          Toast.LENGTH_LONG).show();
              } else {
                  mNfcPendingIntent = PendingIntent.getActivity(NFCActivity.this,
                          0, new Intent(NFCActivity.this, NFCActivity.class)
                                  .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
              }
          }
      }
  
      @Override
      protected void onNewIntent(Intent intent) {
          setIntent(intent);
      }
  
      @Override
      protected void onPause() {
          super.onPause();
          mNFCAdapter.disableForegroundDispatch(this);
      }
  
      @Override
      public void onResume() {
          super.onResume();
          try {
              mNFCAdapter.enableForegroundDispatch(this, mNfcPendingIntent, null,
                      null);
              Tag mTag = getIntent().getParcelableExtra(NfcAdapter.EXTRA_TAG);
  
              byte byteId[] = mTag.getId();
  
              int size = byteId.length;
              // Convert the byte array to integer
              String str = "";
              if (size &gt; 0) {
                  for (int i = 0; i &lt; size; i++) {
                      byte myByte = byteId[i];
                      int myInt = (int) (myByte &amp; 0xFF);
                      str += myInt;
                  }
              }
  
              SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(
                      "yyyyMMddhhmmss");
  
              SharedPreferences mSharedPreferences = PreferenceManager
                      .getDefaultSharedPreferences(getApplicationContext());
              boolean mRegistrationStatus = mSharedPreferences.getBoolean(
                      "registration_status", false);
              boolean mExpiredStatus = mSharedPreferences.getBoolean(
                      "expire_status", true);
  
              Editor mEditor = mSharedPreferences.edit();
  
              if (mRegistrationStatus &amp;&amp; !mExpiredStatus) {
  
                  // Tag here started to scan the the NFC tags
                  mEditor.putString("message", "Tag Read in");
                  mEditor.commit();
  
                  if (Util.isDeviceConnectedWithInternet(this)) {
                      // Upload the NFC details.
  
                      // Start the service and send the NFC Tag Info in the
                      // intent.
                      Intent serviceIntent = new Intent(this,
                              UploadNFCTagInfoService.class);
  
                      serviceIntent.putExtra("mNFCSerialNumber", str);
                      serviceIntent.putExtra("mNFCScannedTimeStamp",
                              mSimpleDateFormat.format(new Date()));
                      startService(serviceIntent);
  
                  } else {
  
                      // Device is not connected with the Internet.
                      // Store the NFC Tag details in the SQLite database.
                      // When device connect with Internet later then
                      // these records will be uploaded on the database server.
  
                      Toast.makeText(this, getString(R.string.network_message), Toast.LENGTH_LONG).show();
  
                      mEditor.putString("message", "Tag has been saved in the application database to upload it later if your device is activated");
                      mEditor.commit();
  
                      NFCIItem mNFCItem = new NFCIItem();
                      mNFCItem.setSerialNumber(str);
                      mNFCItem.setScanTimeStamp(mSimpleDateFormat
                              .format(new Date()));
  
                      // Insert the record in the database.
                      DatabaseManager.getInstance().addNFCTag(mNFCItem);
  
                  }
              } else if(!mRegistrationStatus) {
                  mEditor.putString("message", "Device is not activated to scan NFC Tags");
                  mEditor.commit();
              }
              finish();
          } catch (Exception e) {
              finish();
          }
      }
  }
  </code></pre>