Android 4.4 Service Bluetooth does not exist - android

I tried to toggle Bluetooth from Terminal with the following command as root:
'service call bluetooth 3' for enable
'service call bluetooth 4' for disable
But I get the error
service: service bluetooth does not exist
I searched for bluetooth in the server list and there's only bluetooth_manager
I have a rooted Nexus 5 (Android 4.4).
Is there any other way to toggle Bluetooth via Terminal?
Maybe with 'am start com.android.settings....' ?
What I want to do is enabling Wifi and disable Bluetooth at the same time and reverse.
For Wifi there's no problem with svc wifi enable/disable

As root using service call:
adb shell su -c service call bluetooth_manager 6 turn bluetooth on
adb shell su -c service call bluetooth_manager 8 turn bluetooth off
Details of bluetooth_manager in android.bluetooth.IBluetoothManager.
Or as non-root using keyevents:
adb shell am start -a android.settings.BLUETOOTH_SETTINGS
adb shell input keyevent 19
adb shell input keyevent 23

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.

ADB shell bluetooth commands [duplicate]

I am working on automating bluetooth actions on android like enable/disable, pairing/unpairing devices etc.
I want to know how to interact with unrooted android device for above mentioned bluetooth operations using adb shell commands or android intents.
For example, i want to know which devices are bluetooth paired with my android phone using adb shell commands.
is it possible?
dumpsys is your friend:
Find your bluetooth service (must be running): adb shell dumpsys -l
Mine is bluetooth_manager, so I run: adb shell dumpsys bluetooth_manager
In output you can find section "Bonded devices"

ADB command Enable/Disable NFC for MOS

I'm trying to create a batch file to test for NFC on/off, so I went to the following post to figure out how to programmatically turn NFC on/off using adb command on MOS device:
Enable/Disable NFC with ADB command
Turning on the NFC worked using the following command : adb shell service call nfc 6.
However, turning off NFC isn't working. I tried the following commands:
adb shell service call nfc 0
adb shell service call nfc 1
adb shell service call nfc 2
adb shell service call nfc 3
adb shell service call nfc 4
adb shell service call nfc 5
adb shell service call nfc 7
adb shell service call nfc 8
adb shell service call nfc 9
but none of them worked. "adb shell service call nfc 5" worked in L-OS device, but not in MOS device. How can I turn off NFC using adb command in MOS device? What changes did Google make?
I searched and found this on XDA. Maybe you should give it a try.
NFC POWER OFF
echo 0 > /sys/devices/platform/nfc-power/nfc_power 0<&- &>/dev/null 2>&1

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

How to control bluetooth operations using adb shell?

I am working on automating bluetooth actions on android like enable/disable, pairing/unpairing devices etc.
I want to know how to interact with unrooted android device for above mentioned bluetooth operations using adb shell commands or android intents.
For example, i want to know which devices are bluetooth paired with my android phone using adb shell commands.
is it possible?
dumpsys is your friend:
Find your bluetooth service (must be running): adb shell dumpsys -l
Mine is bluetooth_manager, so I run: adb shell dumpsys bluetooth_manager
In output you can find section "Bonded devices"

Categories

Resources