How to enable NFC setup

I can read and use NFC in my demo application, but I need to check if the NFC option is enabled in the settings menu or not. If it is not turned on, I want to direct the user to the settings menu (I know how to do it), similar to NXP's NFC TagWriter.   enter image description here

In my application, I am using the next version of the SDK

<uses-sdk android:minSdkVersion="7" />
<uses-sdk android:maxSdkVersion="16"/>

I cannot check if this option is enabled or not.

+5
source share
3 answers

TNR is fixed, however also note that from the Android version 16 for NFC there is a more specific action:

protected void startNfcSettingsActivity() {
        if (android.os.Build.VERSION.SDK_INT >= 16) {
            startActivity(new Intent(android.provider.Settings.ACTION_NFC_SETTINGS));
        } else {
            startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));
        }
    }
+11
source

Use the code below to get the NFCAdapter.

NfcAdapter nfcAdpt = NfcAdapter.getDefaultAdapter(this);
if(nfcAdpt!=null)
{
if(nfcAdpt.isEnabled())
{
//Nfc settings are enabled
}
else
{
//Nfc Settings are not enabled
}
}

If you want to go to the NFC user settings, use the code below

Intent setnfc = new Intent(Settings.ACTION_WIRELESS_SETTINGS);                             
startActivity(setnfc);

NFC API 7.

<uses-sdk android:minSdkVersion="10" />
<uses-sdk android:maxSdkVersion="16"/>
+1
    if (Build.VERSION.SDK_INT >= 10) {
        i = new Intent("android.settings.NFC_SETTINGS");
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(i);
    } else {
        i = new Intent(Settings.ACTION_WIRELESS_SETTINGS);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(i);
    }
0
source

All Articles