Is there an easy way to get the version name of an application on Android devices using adb shell?
I've already find this command from here:
adb shell dumpsys package my.package | grep versionName
But I don't know how can I use it for more that one device?!
You cannot run an adb command on multiple devices in my experience but if you have multiple devices then adb command to run on specific devices becomes as follows:
adb [-d|-e|-s <serialNumber>] <command>
-d means run on the connected device (results in error for more than one connected device)
-e means run on the simulator (results in error for more than one simulator)
-s means use specific serial number
serial number used in -s is obtained with adb devices command.
a sample output of this command is:
List of devices attached
cf264b8f device
emulator-5554 device
for no device connected the first line is only printed
Output format is [serialNumber] [state], serialNumber that is, we often say that the SN, state the following categories:
Offline: indicates that the device is not connected to the success or unresponsive.
Device: device is connected. Note that this state does not identify the Android system has been fully activated and operational in the device during startup device instance can be connected to the adb, but after boot the system before it becomes operational.
No device: no device / emulator connection.
Related
I am running QtScrcpy to mirror and control multiple android devices from PC (win). In the same time running Python script which remote stepper motors (turntable). What I need is to send command adb shell input keyevent 24 to android devices via Python somehow.
You can use AndroidViewClient/culebra and create a script like this (this is a minimalistic version)
#! /usr/bin/env python3
from com.dtmilano.android.viewclient import ViewClient
ViewClient.connectToDeviceOrExit()[0].press('VOLUME_UP')
I am able to connect an Android device with ADB using a USB cable but I want to connect a remote device without a USB cable, and not rooted also. I am running the ADB command through Python. I have been googling for 2 days and most of the resources say we can't do this. If it's not possible, please suggest other options.
Is this possible with a Python script?
I am trying to simulate tap and swipe gesture from adb to my android device. I've tried to run the following command
adb shell input tap 500 500 and adb shell input touchscreen tap 500 500 from windows command prompt. It is giving me the following error,
java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission
at android.os.Parcel.createException(Parcel.java:2074)
at android.os.Parcel.readException(Parcel.java:2042)
at android.os.Parcel.readException(Parcel.java:1990)
at android.hardware.input.IInputManager$Stub$Proxy.injectInputEvent(IInputManager.java:925)
at android.hardware.input.InputManager.injectInputEvent(InputManager.java:886)
at com.android.commands.input.Input.injectMotionEvent(Input.java:428)
at com.android.commands.input.Input.access$200(Input.java:41)
at com.android.commands.input.Input$InputTap.sendTap(Input.java:224)
at com.android.commands.input.Input$InputTap.run(Input.java:218)
at com.android.commands.input.Input.onRun(Input.java:108)
at com.android.internal.os.BaseCommand.run(BaseCommand.java:56)
at com.android.commands.input.Input.main(Input.java:71)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:380)
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.input.InputManagerService.injectInputEventInternal(InputManagerService.java:732)
at com.android.server.input.InputManagerService.injectInputEvent(InputManagerService.java:706)
at android.hardware.input.IInputManager$Stub.onTransact(IInputManager.java:422)
at android.os.Binder.execTransactInternal(Binder.java:1021)
at android.os.Binder.execTransact(Binder.java:994)
I've also tried to execute the same command from python script with the pure-python-adb package. The following is script I've exucted.
from ppadb.client import Client
adb = Client()
devices = adb.devices()
if len(devices) == 0:
print("No devices attached")
quit()
device = devices[0]
print(device)
device.shell('input touchscreen tap 700 1453')
I got the following output with no tap noticed on device and no error from the script.
<ppadb.device.Device object at 0x02B30E50>
Am I missing anything (Might be in developer's option setting for android)?
I am on windows 10 machine with adb version 1.0.41. And using an android device with Android 10 (Android Q) over a usb.
Look for a "USB debugging (Security Settings)" or something similar in your developer options in the debugging section -- This is where you grant ADB special permissions and allow input.
Best of luck; I hope you find it.
I tried this to tap a xy coordinate using adb command. Enabling the "USB debugging (Security Settings)" is worked for me. But the phone should connect to the internet inorder to enable the settings.
Thanks #Meer
I am trying to automate android mobile using python's pure-python-adb package but when I run the following code:
from ppadb.client import Client as AdbClient
# Default is "127.0.0.1" and 5037
client = AdbClient(host="127.0.0.1", port=5037)
print(client.version())
I get error in Pycharm as:
RuntimeError: ERROR: connecting to 127.0.0.1:5037 [WinError 10061] No connection could be made because the target machine actively refused it.
Is adb running on your computer?
Please can anyone help me with it
Switch on developer mode in your phone and connect it to your laptop using a physical data transfer (or changing) cable.
REMEMBER: Switch on 'USB debugging' on your phone.
Then go to cmd terminal and make sure you have adb requirements from android studio installed. Once that's there, go to terminal and type.
adb devices
if your phone shows up, you should be connected. You can then type
adb shell
or:
adb connect tcpip 5555
to connect over the internet
I'm pretty new to Bluetooth so this might be trivial, but I'll still ask:
I would like to connect 2 devices via Bluetooth - a mobile device with a Linux device (like Raspberry Pi, but another one...).
Side 1 - the mobile: It has an app that should pair with the Linux device, and send some data to it (a msg with "Hello" in this point).
Side 2 - the linux device: It should have a kind of listener to the fact that a device was connected to it via bluetooth, and then expect the data, receive it, and process it.
Side 1 is all fine and clear to me.
As for side 2, for now I only use some command line commands to turn Bluetooth on, set some name to the device, and wait for scan. I do it with "hciconfig", by running the following commands in Python script, one after the other:
hciconfig hci0 up
hciconfig hci0 name MyDevice
hciconfig hci0 sspmode 1
hciconfig hci0 piscan
At this point, my device is discover-able to my mobile and it pairs with it successfully. Now, I'm stuck with the listening part. I would like the linux device to run a certain function (prefer in Python) when the device is paired, and expect to receive data from it. I've read some links over the net, using RFCOMM and Bluez, but none succeeded...
Can someone please assist?
Thanks
Good morning, there is a library written in Python that handle Bluetooth connection for you already PyBluez
to install use sudo pip install pybluez
here is an example on how to use sockets to communicate with bluetooth devices
import bluetooth
bd_addr = "01:23:45:67:89:AB"
port = 1
sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
sock.connect((bd_addr, port))
sock.send("hello!!")
sock.close()
the complete guide is at Bluetooth Programming with PyBluez
`