title: getting UID of NFC in Android
body: <p>I am learning Android and NFC programming through the official android developer tutorial. What I want is to write an app that will be triggered by NFC tag. When the app starts, I want it to display a toast message containing the UID of the scanned tag. My simple code to achieve this is: </p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Tag tag = getIntent().getParcelableExtra(NfcAdapter.EXTRA_TAG);
    Toast.makeText(getApplicationContext(), "UID: " + bin2hex(tag.getId()),    Toast.LENGTH_SHORT).show();
  }
  // Parsing binary to string
  static String bin2hex(byte[] data) {
      return String.format("%0" + (data.length * 2) + "X", new BigInteger(1,data));
  }
  </code></pre>
  
  <p>I also update the manifest file to enable NFC as shown below:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.NFC"/&gt;
    ....
  &lt;uses-feature android:name="android.hardware.nfc" android:required="true" /&gt;
  
  &lt;application  
      &lt;activity
          android:name="com.testapp.testnfc.MainActivity"
          android:label="@string/app_name" &gt;
          .....
          &lt;intent-filter&gt;
              &lt;action android:name="android.nfc.action.NDEF_DISCOVERED"/&gt;
              &lt;category android:name="android.intent.category.DEFAULT"/&gt;
              &lt;data android:mimeType="text/plain" /&gt;
     &lt;/intent-filter&gt;
      &lt;/activity&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p>Then I use "NFC Task Launcher" app from Play Store to write into my tag so that the tag will trigger my new app. After creating the tag, tapping on it will successfully start my new app, but the app fails to display the toast of the UID and it will crash stating "Unfortunately Test NFC has stopped." What did I miss to cause this crash?</p>