Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable NFC setting

Tags:

android

nfc

I am able to read and wirte in my NFC demo app but I need to check if the NFC option in setting menu is enabled or not . If its not enable I want to direct the user to the setting menu(I know how to do this) similar to NFC TagWriter by NXP. enter image description here

In my application I am using the following SDK version

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

I am unable to check if the setting is enabled or not.

like image 299
MRX Avatar asked Feb 19 '13 12:02

MRX


2 Answers

TNR gets it right, however also note that from Android version 16, there is a more specific settings action for NFC:

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));
        }
    }
like image 192
ThomasRS Avatar answered Nov 08 '22 22:11

ThomasRS


Use the below code 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 navigate user to Settings of NFC then use below Code

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

There is no NFC for API version 7. So change you manifest file as below

<uses-sdk android:minSdkVersion="10" />
<uses-sdk android:maxSdkVersion="16"/>
like image 39
TNR Avatar answered Nov 08 '22 22:11

TNR