I am unable to figure out , how do I switch on the NFC feature from my android application instead of doing it from the settings. Just the way we can switch Bluetooth on, can it be similarly done for NFC ? I have seen the NFCAdapter Documentation, but coudnt find the appropriate method.
Asked
Active
Viewed 3,810 times
3 Answers
3
You can redirect the user to the settings when you detect that NFC is turned off:
// Take the user to the wireless settings panel, where they can enable NFC
final Intent intent = new Intent(Settings.ACTION_WIRELESS_SETTINGS);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivity(intent);

NFC guy
- 10,151
- 3
- 27
- 58
-
so basically i should do something like this `code` if (!nfcAdapter.isEnabled()) // and then follow what you have written above. – tanuj Mar 11 '12 at 07:23
-
let me first explain why i asked this particular question. My app first starts with a authentication and after that there is an another activity in which , product ids are retrieved from nfc tags , and the corresponding information of the product is populated in a list view. So if a user taps on 10 different tags, there will be a list view with 10 different items. Suppose a particular user is simply on the homescreen and exploring other features of the app, and he still taps on a tag , how will the app behave then ? I want the list population feature to run only in its respective activity. – tanuj Mar 11 '12 at 12:45
-
I am still waiting for your response. – tanuj Mar 12 '12 at 19:05
-
I don't follow how your follow-up question is related to your original question about turning on NFC and my answer to that... – NFC guy Mar 13 '12 at 08:49
-
is there any other medium to get assistance from you ? Like some other platform or any social media, where i can directly get in touch with you. My project revolves around nfc and i think your assistance and knowledge will be of great help to me. – tanuj Mar 14 '12 at 18:29
-
If you leave your email address, I can follow up. – NFC guy Mar 15 '12 at 21:04
-
tanuj_stackoverflow@hotmail.com – tanuj Mar 16 '12 at 05:16
-
Hi tanuj, can you please provide me any example that should work for API level 19. As I tried with this link: stackoverflow.com/questions/1975655/…ie is not opening. – Anchal Radhwani Jun 15 '16 at 10:39
2
Just the way we can switch Bluetooth on, can it be similarly done for NFC ?
You cannot "switch Bluetooth on" programmatically "instead of doing it from the settings". Whether Bluetooth is enabled or not is a secure setting. Similarly, whether NFC is enabled or not can only be done via the Settings app.

CommonsWare
- 986,068
- 189
- 2,389
- 2,491
-
http://stackoverflow.com/questions/1975655/enable-android-bluetooth-from-documentation I thought one can programmatically switch on Bluetooth. I referred the above mentioned link. – tanuj Mar 11 '12 at 07:28
-
@tanuj: That does not enable Bluetooth -- it allows the *user* to enable Bluetooth. The user can always say no. I am not aware of an equivalent of `BluetoothAdapter.ACTION_REQUEST_ENABLE`, unfortunately. NFC guy's answer is as close as you are going to get. – CommonsWare Mar 11 '12 at 11:54
0
You can use reflection to get the methods enable() and disable() from the NfcAdapter object.
They are there, they are just hidden in the API.

Nils Pipenbrinck
- 83,631
- 31
- 151
- 221
-
1Accessing them requires special permissions since Android 2.3.6, so that solution does not work anymore. – NFC guy Mar 10 '12 at 23:48
-
-
@AnchalRadhwani The answer is 4 years old. It doesn't work anymore. – Nils Pipenbrinck May 10 '16 at 12:13
-
@Nils Pipenbrinck: Is there is any other way to enable/disable nfc from android application itself? – Anchal Radhwani Jun 15 '16 at 10:40