Check if the NFCAdapter is enable - Android Network

Android examples for Network:NFC

Description

Check if the NFCAdapter is enable

Demo Code


//package com.java2s;

import android.content.Context;

import android.nfc.NfcAdapter;

public class Main {
    /**/*from w  w  w . j a  va  2  s  . c o  m*/
     * Check if the NFCAdapter is enable
     * 
     * @return true if the NFCAdapter is available enable
     */
    public static boolean isNfcEnable(final Context pContext) {
        boolean ret = true;
        try {
            NfcAdapter adpater = NfcAdapter.getDefaultAdapter(pContext);
            ret = adpater != null && adpater.isEnabled();
        } catch (UnsupportedOperationException e) {
            ret = false;
        }
        return ret;
    }
}

Related Tutorials