Android: Changing Nfc Settings (On/Off) Programmatically

Android: Changing NFC settings (on/off) programmatically

You can not turn it on/off manually but you can send the user to the preferences if it is off:

    if (!nfcForegroundUtil.getNfc().isEnabled())
{
Toast.makeText(getApplicationContext(), "Please activate NFC and press Back to return to the application!", Toast.LENGTH_LONG).show();
startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));
}

Method getNfc() just returns the nfcadapter:

nfc = NfcAdapter.getDefaultAdapter(activity.getApplicationContext());

Disable NFC through DevicePolicyManager in android studio

Apparantly there is no straightforward way to disable NFC by means of DevicePolicies according to the official documentation.
There are some options that include the term NFC but it seems it's mostly related to provisioning.

Most answers or documentation suggests to disable NFC by accessing the Adapter programmatically (see linked answer;which is not what you asked for).
In addition, most answers emphasize that the approach is not applicable to "normal" devies. It requires root access to disable the adapter. That may be a limiting for you as well.

For what it's worth, a custom device policy could be a promising lead. I'd advise to research that option.
Alternatively, if you can you could inform the user that NFC has to be turned off upon App start and quit otherwise.

Change android settings programmatically

If I understand you correctly, you want to take the user to the NFC section of the Device Settings (via a Toast or something similar). If this is correct, then using Robotium you will be able to trigger and action the Toast, but once you are in the device settings, Robotium cannot make the actual selection.

Android Instrumentation actions are confined to a single package (the one under test).

Take a look at UIAutomater, this may help.

Can an Android app change the settings of the phone such as sound on/off wi-fi on/off?

It is possible to mute the phone with programtically, however to change the WiFi on/off, you need to send the user to settings screen for them to do it manually

Here is a link to mute your phone - Android mute/unmute phone

And here is the code to send the used to settings

startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));

Taken from Android: Changing NFC settings (on/off) programmatically



Related Topics



Leave a reply



Submit