title: read RFID tag using NFC
body: <p>I want to develop a android application witch can read the ID of a RFID card(mifare classic type A) usin NFC but my Application detect the card but it does not return any thing .. help please btw i hqve 2 class </p>
  
  <p>class MainActivity:</p>
  
  <pre><code>package com.example.nfcreader;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.nfc.NfcAdapter;
  import android.nfc.Tag;
  import android.os.Bundle;
  import android.widget.TextView;
  import android.widget.Toast;
  
  public class MainActivity extends Activity {
  static String TAG = "NFCREADER";
  
  NFCForegroundUtil nfcForegroundUtil = null;
  
  private TextView  info;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
     info = (TextView)findViewById(R.id.title);
  
      nfcForegroundUtil = new NFCForegroundUtil(this);
  }
  
  public void onPause() {
      super.onPause();
      nfcForegroundUtil.disableForeground();
  }   
  
  public void onResume() {
      super.onResume();
      nfcForegroundUtil.enableForeground();
  
      if (!nfcForegroundUtil.getNfc().isEnabled())
      {
          Toast.makeText(getApplicationContext(), 
                  "Please activate NFC and press Back to return to the application!", 
                  Toast.LENGTH_LONG).show();
          startActivity(
                  new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));
      }
  
  }
  
  public void onNewIntent(Intent intent) {
      Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
      /*StringBuilder sb = new StringBuilder();
      for(int i = 0; i &lt; tag.getId().length; i++){
          sb.append(new Integer(tag.getId()[i]) + " ");
      }*/
     info.setText("TagID: " + bytesToHex(tag.getId()));    
      //byte[] id = tag.getId();
  }
  
  /**
   *  Convenience method to convert a byte array to a hex string.
   *
   * @param  data  the byte[] to convert
   * @return String the converted byte[]
   */
  
  public static String bytesToHex(byte[] data) {
      StringBuffer buf = new StringBuffer();
      for (int i = 0; i &lt; data.length; i++) {
          buf.append(byteToHex(data[i]).toUpperCase());
          buf.append(" ");
      }
      return (buf.toString());
  }
  
  /**
   *  method to convert a byte to a hex string.
   *
   * @param  data  the byte to convert
   * @return String the converted byte
   */
  public static String byteToHex(byte data) {
      StringBuffer buf = new StringBuffer();
      buf.append(toHexChar((data &gt;&gt;&gt; 4) &amp; 0x0F));
      buf.append(toHexChar(data &amp; 0x0F));
      return buf.toString();
  }
  
  /**
   *  Convenience method to convert an int to a hex char.
   *
   * @param  i  the int to convert
   * @return char the converted char
   */
  public static char toHexChar(int i) {
      if ((0 &lt;= i) &amp;&amp; (i &lt;= 9)) {
          return (char) ('0' + i);
      } else {
          return (char) ('a' + (i - 10));
      }
    }    
  
  }
  </code></pre>
  
  <p>class NFCForegroundUtil:</p>
  
  <pre><code>package com.example.nfcreader;
  
  import android.app.Activity;
  import android.app.PendingIntent;
  import android.content.Intent;
  import android.content.IntentFilter;
  import android.content.IntentFilter.MalformedMimeTypeException;
  import android.nfc.NfcAdapter;
  import android.nfc.tech.NfcA;
  import android.util.Log;
  
  public class NFCForegroundUtil {
   private NfcAdapter nfc;
  
  private Activity activity;
  private IntentFilter intentFiltersArray[];
  private PendingIntent intent;
  private String techListsArray[][];
  
  public NFCForegroundUtil(Activity activity) {
      super();
      this.activity = activity; 
      nfc = NfcAdapter.getDefaultAdapter(activity.getApplicationContext());
  
      intent = PendingIntent.getActivity(activity, 0, new Intent(activity,
              activity.getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
  
      IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
  
      try {
          ndef.addDataType("*/*");
      } catch (MalformedMimeTypeException e) {
          throw new RuntimeException("Unable to speciy */* Mime Type", e);
      }
      intentFiltersArray = new IntentFilter[] { ndef };
  
      techListsArray = new String[][] { new String[] { NfcA.class.getName() } };
  
  }
  
  public void enableForeground()
  {
      Log.d("demo", "Foreground NFC dispatch enabled");
      nfc.enableForegroundDispatch(
              activity, intent, intentFiltersArray, techListsArray);     
  }
  
  public void disableForeground()
  {
      Log.d("demo", "Foreground NFC dispatch disabled");
      nfc.disableForegroundDispatch(activity);
  }
  
  public NfcAdapter getNfc() {
      return nfc;
    }   
  }
  </code></pre>
  
  <p>and my AndroidManifest </p>
  
  <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.nfcreader"
  android:versionCode="1"
  android:versionName="1.0" &gt;
  
   &lt;uses-sdk 
     android:minSdkVersion="10"
     android:targetSdkVersion="20" /&gt;
  &lt;uses-permission android:name="android.permission.NFC" /&gt;
  &lt;uses-feature android:name="android.hardware.nfc" android:required="true" /&gt;
  
     &lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
      &lt;activity
          android:name=".MainActivity"
          android:label="@string/app_name" &gt;
           &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-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;
  &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>