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
Android 5.0: How to Change Recent Apps Title Color
Cannot Deserialize Instance of Object Out of Start_Array Token in Spring Webservice
How to Handle Basic Authentication in Webview
No Peer Certificate' Error in Android 2.3 But Not in 4
Android Shape Border with Gradient
Android Repeat Action on Pressing and Holding a Button
Android - How to Intercept the 'Install Application' Intent
Mediametadataretriever Setdatasource Throws Illegalargumentexception
How to Get Dependencies from Jcenter with a New Project
Could Not Resolve Com.Android.Support:Appcompat-V7:26.1.0 in Android Studio New Project
Setting a Maximum Width on a Viewgroup
How to Apply Plugin to Only One Flavor in Gradle
How to Have 1 Firebase Database for 2 Apps with Different Package Names
Android UI Design: Supporting Multiple Screens
Highlighting the Selected Item in the Listview in Android
Android Audiotrack Playing .Wav File, Getting Only White Noise