enable NFC Foreground - Android Network

Android examples for Network:NFC

Description

enable NFC Foreground

Demo Code


import android.app.Activity;
import android.app.PendingIntent;
import android.nfc.NdefMessage;
import android.nfc.NfcAdapter;

public class Main {
  private static NfcAdapter nfcAdapter = null;
  private static NdefMessage ndefMsg = null;
  private static PendingIntent pendingIntent = null;

  public static void enableForeground(Activity activity) {

    if (!isAvailable())
      return;//  ww  w.  j  a va 2 s. c o  m

    nfcAdapter.enableForegroundDispatch(activity, pendingIntent, null, null);

    nfcAdapter.enableForegroundNdefPush(activity, ndefMsg);
  }

  public static Boolean isAvailable() {
    if (nfcAdapter != null && nfcAdapter.isEnabled())
      return true;
    else
      return false;
  }
}

Related Tutorials