Native Android Device > turn off/on NFC with ADB [duplicate] - android
This question already has answers here:
Enable/Disable NFC with ADB command
(6 answers)
Closed 5 years ago.
Is it possible to turn off/on (disable/enable) NFC with ADB for non-rooted Android device with v 6.0.1 version or higher?
i tried many stuff but it wont work for me.
Stuff i tried are:
Via ADB:
adb shell settings put global airplane_mode_toggleable_radios bluetooth,cell,wimax,nfc
adb shell am broadcast -a android.intent.action.airplane_mode_toggleable_radios
adb shell settings put global airplane_mode_on 1
adb shell am broadcast -a android.intent.action.AIRPLANE_MODE
adb shell settings put global radio_nfc 0
adb shell am broadcast -a android.intent.action.radio_nfc
adb shell settings put global AIRPLANE_MODE_RADIOS 0
adb shell am broadcast -a android.intent.action.AIRPLANE_MODE_RADIOS
adb shell settings put global NfcAdapter 0
adb shell am broadcast -a android.intent.action.NFC_adapter
adb shell settings put global airplane_mode_radios cell,bluetooth,nfc,wimax
adb shell content update --uri content://settings/global --bind value:s:'bluetooth,nfc,wimax' --where "name='airplane_mode_radios'"
also:
adb shell settings get global airplane_mode_radios
adb shell content query --uri content://settings/global --projection name:value --where "name='airplane_mode_radios'"
adb shell settings put global airplane_mode_radios "cell,nfc,wimax"
adb shell content update --uri content://settings/global --bind value:s:'cell,nfc,wimax' --where "name='airplane_mode_radios'"
adb shell settings put global airplane_mode_radios "cell,bluetooth,wifi,nfc,wimax"
adb shell content update --uri content://settings/global --bind value:s:'cell,bluetooth,wifi,nfc,wimax' --where "name='airplane_mode_radios'"
After restarting the device i can turn ON the airplane-mode with ADB but the nfc does NOT go off.
As i turn ON the airplane-mode on the native device (quick settings OR settings) it does go off!
Another one i tried is:
List the running services with:
adb shell service list
there you can read that nfc is running at number 9 " nfc: [android.nfc.INfcAdapter] "
try to disable with
adb shell pm hide com.android.nfc
does not work and throws:
Error: java.lang.SecurityException: Neither user 2000 nor current process has android.permission.MANAGE_USERS.
or:
adb shell pm grant EXAMPLE.android.services android.permission.WRITE_SECURE_SETTINGS
adb shell pm grant EXAMPLE.android.services android.permission.CHANGE_CONFIGURATION
-
following is working on devices up to Android 5x:
Enable/Disable NFC with ADB command
After playing around with Enable/Disable NFC with ADB command
On android Marshmallow (6.0.0 or 6.0.1)
Disable
service call nfc 5
Enable
~~service call nfc 6~~
Edit:
This doesn't seem to disable permanently, rebooting re-enables the service
Found the real answer!
svc nfc <enable|disable>
Related
I want to enable or say start WiFi tethering in android device by executing adb shell command
I want to enable hotspot or say start WiFi tethering in android device by executing adb shell command. What is the adb command used for it? To turn on bluetooth - adb shell am start -a android.bluetooth.adapter.action.REQUEST_ENABLE. To open wifi- adb shell am start -n com.android.settings/.wifi.WifiSettings. But I can not find for turning on hotspot.
How to verify that phone is connected to any cellular service provider?
I found how to call , but even when the device has no sim card it returns no error, so it doesn't help me: adb -s <device number> shell am start -a android.intent.action.CALL -d tel:55678888
You can read the content of telephony.registry by using - adb shell dumpsys telephony.registry and then parse it. Look for the value of mServiceState: 0 - In Service 1 - Out of Service 2 - Emergency Only
adb shell "watch" command to monitor
I am trying to monitor some commands in my adb shell and I could go watch adb shell <command> but the extra time to have to connect up to the shell is killing me. Does the Android adb shell have its own version of watch so I can monitor some commands
while true; do <command>; sleep 2; done
How to verify WIFI wake lock using adb command
Can someone tell me is there any adb command to verify wifi wake lock in android phone. I am trying to check that wake lock is active or not after acquire from my application but not found this information in following file: adb shell "cat /sys/kernel/debug/wakeup_sources" Is it written somewhere else ?
To list the wifilocks active in android device, use the following command. adb shell dumpsys wifi | grep "your wake_lock tag name" Example: adb shell dumpsys wifi | grep wake_lock_next output: WifiLock{wake_lock_next type=2 binder=android.os.BinderProxy#420bcfd0}
How to test wifi connection via adb?
Im automating wifi off/on via adb. I would either like to disable/enable wifi based on the test case so far I have found good information here However I want to test the connection before executing following command adb shell am start -a android.intent.action.MAIN -n com.android.settings/.wifi.WifiSettings adb shell input keyevent 19 & adb shell input keyevent 19 & adb shell input keyevent 23 Above command disables wifi if enabled, enables wifi if disabled. I want to first test the connection and take action if required. I am wondering if there is a way to do using adb command. This can be achieved programatically but I want it to be done through adb for making it more reliable. Also following command works only if device is rooted adb shell "svc wifi enable" Also following command launches test on screen but provides no info via adb adb shell am start -n com.android.settings/.wifi.WifiStatusTest
To know everything about Wifi status of the device: adb shell dumpsys wifi To just know whether it's enabled or not: adb shell dumpsys wifi | grep "Wi-Fi is" To know more detailed status: adb shell dumpsys wifi | grep "mNetworkInfo" If connected to a valid network, it shows "CONNECTED/CONNECTED". It also shows the name of the connected network. If wifi has been enabled but it is yet to connect to a network, it shows "DISCONNECTED/SCANNING". If wifi is disabled, it shows "DISCONNECTED/DISCONNECTED".
Below command will give you the internet status and connectivity mode(cellular or Wi-Fi) adb shell dumpsys connectivity
If you're trying to determine whether or not WiFi is turned on you can run adb shell settings get global wifi_on which returns 1 if it's on and 0 if it's off. If you have multiple devices connected you can run adb -s [UDID_HERE] shell settings get global wifi_on to get the WiFi status of an individual phone. To find the UDID you can run adb devices.
This would only tell you if there is internet access but you can do: adb shell ping www.google.com
adb shell dumpsys wifi | sed -n '1p' is faster and safer than adb shell dumpsys wifi | grep "Wi-Fi is" because the output of dumpsys wifi contains the system logs that may have been contaminated by other applications
Atish's answer was working fine until Android 11/R. For this OS onwards, I recommend using Abhishek's suggestion: adb shell dumpsys wifi | grep "curState=ConnectedState"
Not perfect, but you could dump UI layout and then search for ON/OFF text like this (bash): adb pull $(adb shell uiautomator dump | grep -o '[^ ]*.xml') ui.xml grep 'text="OFF"' ui.xml if [ $? == 0 ]; then # Turn WIFI on fi