Android Code Snippet Check if a device has NFC and it's status

Hi all, i'm working on an NFC app and i need to know if a device has NFC capabilities and if it's enabled or not.
The current nfc library doesn't have this function so i decided to write this piece of code and share it with you.

To do this i reused some pieces of useful code to get the BA.context from here:
https://www.b4x.com/android/forum/threads/problem-with-additionaljar-javaobject-and-context.48958/
all credits to his author.

The uploaded code is commented and self-explanatory, you need at least api 10 to compile this and NFC permission in manifest.
It uses javaobject and phone library

With this code you can:
-check if a device is NFC capable
-check if the NFC hardware is enabled or disabled
-Open the NFC settings screen

Bye
DavideV
 

Attachments

  • NFCtestapp.zip
    8.3 KB · Views: 535
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Nice. It´s working fine here. Thank you for sharing...
 

raphaelcno

Active Member
Licensed User
Longtime User
Hi all, i'm working on an NFC app and i need to know if a device has NFC capabilities and if it's enabled or not.
The current nfc library neither the other libs i found in the forum have this function so i decided to write this piece of code and share it with you.
With this code you can:
-check if a device is NFC capable
-check if the NFC hardware is enabled or disabled
-Open the NFC settings screen

It is also possible to use the NfcForeground library
https://www.b4x.com/android/forum/t...library-nfc-foreground-dispatch-system.31141/
which contains following methods:
- NfcExists
- NfcEnabled
 
Top