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"
Related
I have some old shell scripts that needs to be executed on an android device but the command to fetch the total cpu, memory and swap usage is top. More specific it is:
top -m 1 -d 1.0 -n $duration
Now I have been looking to find a replacement for this and I found out that I can use dumpsys. The problem what I have is that I want to give a timeout like this:
dumpsys -t 20 cpuinfo
I checked this site: https://developer.android.com/studio/command-line/dumpsys.html but didn't find out why this doesn't work. Even when I try the help I get the same error
dumpsys --help
Can't find the service: --help
Does someone know what is going on? My current android version is 6.0.1 if this is important.
Thanks in advance!
It is true that dumpsys --help does not work. I think there is a mistake in their document. However, below works:
# adb shell dumpsys input
# adb shell dumpsys -l
Add permission on your manifest "android.permission.DUMP".or
There's another (hacky) way to access dumpsys without rooting your device - through adb shell.
This will require allowing USB debugging, and finding the port of the adb service.
Enable USB debugging on your device. This option is found under Settings -> Developer Options.
Connect your device to a PC, and run the following command from the PC's shell/command line: adb tcpip 12345. Then, from your devices shell, issue the command adb connect localhost:12345 from your application. You can now disconnect the device from USB. Alternatively, you can scan the ports on your device one by one without USB connection, using adb connect localhost: and find the port adb service is listening to.
Authorize USB debugging from the pop up confirmation dialog, if prompted. Check the "always" checkbox to do not require this step again.
Now, when you have access to the adb service, use adb shell dumpsys ... from your application code to get whatever service dump you need.
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"
I have an LG watch which I can connect directly to my developer machine using USB and therefore can use the following command to take screenshots:
adb shell screencap -p /sdcard/screenshot.png
However my Moto 360 watch doesn't have a usb connection and thus I have to connect it using bluetooth going via its paired handset. This means there are always two devices connected to adb. Thus its not possible to use the adb shell command as adb doesn't know which device to apply it to. Some adb commands can have the device specied, but it doesn't look like this is possible with adb shell.
Using the Take wearables screenshot menu option in the Android Wear app isn't doing anything - it says "Screenshot request sent" but then nothing after that.
So how can I grab a screenshot of the watch? (I want to take a screenshot when there is an incoming phone call)
Enable bluetooth debugging on your wearable and setup a debugging session (described here: Debugging over Bluetooth).
You have to run any adb command in the following format:
adb -s localhost:4444 <command>
A simple
adb -s localhost:4444 shell screencap -p /sdcard/screenshot.png
adb -s localhost:4444 pull -p /sdcard/screenshot.png
should do the trick ;)
I'm looking for an adb shell command to enable/disable mobile data. The app is only being tested on rooted devices so I have adb root privileges. I looked around and found that wifi can be enabled/disabled with:
$ adb shell svc wifi enable
$ adb shell svc wifi disable
These work for me but I wasn't able to find anything for mobile data.
Any reference to a list of adb shell svc commands that can be performed would be appreciated as well. I know there's a list of key input commands from this question and obviously I'm aware of the developer page but there's no mention of svc.
Lastly, what is svc?
I found the answer to my question:
To enable mobile data:
$ adb shell svc data enable
To disable mobile data:
$ adb shell svc data disable
Trying to configure ADB so that I can debug it via wifi, I have checked on Google but not getting proper resolution.
Tell me what to enter in port address, device ip.
Moreover setprop service.adb.tcp.port command is running when i give space between set and prop, bit confuse...
Seeking for help
I got the following article, and wanted help in the same context.
disconnect device from usb then tell it to listen on 4455
adb tcpip 4455
restarting in TCP mode port: 4455
connect to the device using a specified ip:port. my device is using wifi
adb connect 192.168.1.103:4455
connected to 192.168.1.103:4455
now do normal adb commands over tcp
adb shell
when your done, you can put it back in USB mode
adb usb
restarting in USB mode
Help me
These are commands for the shell of the android device, not for the host system.
Type adb shell to get the device's shell and then enter them. If you get back to the windows shell prompt you are in the wrong place.
However those commands may not be effective on a secured device anyway.
setprop is an Android command and is meant to be used in a terminal after su on the device (you can do adb shell setprop ... but when you adb shell stop adbd you'll loose your device connection). The easier way if already connected via USB is adb tcpip 8600 and then adb connect IP_OF_PHONE:8600 -- but this will only work if adb shell will get you a root prompt (starts with # and not $). Be aware that anyone on your wifi network can access your device!