Last Updated: December 29, 2017
·
4.081K
· iankitshah

Android: Check NFC Support

1) Add "uses-feature" element in AndroidMenifeast file, so that your application shows up in Google Play only for devices that have NFC hardware

<uses-feature android:name="android.hardware.nfc" android:required="true" />

2) If your application uses NFC functionality, but that functionality is not crucial to your application, you can omit the uses-feature element and check for NFC avalailbility at runtime

**Option 1:**
NfcManager nfcManager = (NfcManager) context.getSystemService(Context.NFC_SERVICE);
NfcAdapter nfcAdapter = nfcManager.getDefaultAdapter();
if (nfcAdapter == null) {
    // Device not compatible for NFC support
}

**Option 2:**
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) {
    // Device not compatible for NFC support
}

3) Check if NFC is enabled... If "False" applications can request Settings UI allowing the user to toggle/enable NFC from Settings

startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));