Enable NFC programmatically on Android device

Balauroiu Radu 41 Reputation points
2021-02-01T08:04:51.623+00:00

Hi,

I'm trying to work with the NFC device and I got to the step where I have to enable the NFC programmatically. I've made a lot of research but I couldn't find anything that works. For example, if you want to enable the Bluetooth device on android you will use BluetoothAdapter.DefaultAdapter.Enable(), but for the NFC device, I couldn't find something similar. Do you guys have any suggestions on how can I enable the NFC device programmatically from the android device?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,298 questions
0 comments No comments
{count} votes

Accepted answer
  1. JarvanZhang 23,951 Reputation points
    2021-02-01T12:51:19.46+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    The NFC is the setting of the device, we cannot disable or enable the function in one application. Instead, you could check if the nfc is enabled, then remind the user to navigate to the setting page if not.

       NfcAdapter nfcAdapter = NfcAdapter.DefaultAdapter;  
       if (nfcAdapter == null)  
       {  
           // NFC is not available for device  
       }  
       else if (!nfcAdapter.IsEnabled())  
       {  
           // NFC is available for device but not enabled  
           StartActivity(new Intent("android.settings.NFC_SETTINGS"));  
       }  
       else  
       {  
           // NFC is enabled  
       }  
    

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Alessandro Caliaro 4,181 Reputation points
    2021-02-01T08:08:00.997+00:00

    XamarinDemoNfc

    I written this some years ago. I don't remeber if I turn on the nfc programmatically... you can take a look