Code Monkey home page Code Monkey logo

Comments (5)

Swind avatar Swind commented on September 17, 2024

Hi selster:
You can use adb devices to list all attached android devices.

$ adb devices
List of devices attached 
YC873P0G    device

The YC873P0G is the device number.

Thanks ~

from pure-python-adb.

selster avatar selster commented on September 17, 2024

Thank you!. But can I get it programmatically, rather than using the command prompt?
The following returns the device number using get_serial_no() (but after I supply the device number):

from adb.client import Client as AdbClient
client = AdbClient(host="127.0.0.1", port=5037)
device = client.device("ZY224VQLW6")
device_number = device.get_serial_no()

but I can't figure out to get the device number by doing:
devices = client.devices()
devices.(something goes here that will return the device number?). I am guessing you have impleted this?
Otherwise in a python script, I could get the device number like this

import subprocess
cmd = "adb devices"
subprocess.check_output(cmd) && and then parse the output to get the device number

from pure-python-adb.

selster avatar selster commented on September 17, 2024

It would be the equivalent of this: subprocess.check_output(cmd).decode('utf8').strip().replace("List of devices attached","").strip()[:-7]

from pure-python-adb.

selster avatar selster commented on September 17, 2024

on my windows 7 systems, shell gives me an error:
device.shell("asdf")
'/system/bin/sh: asdf: not found\n'

In the meantime, this seems to work:

from adb.client import Client as AdbClient
import os
os.chdir(r'C:\Users\se\Downloads\scrcpy-win64-v1.5\scrcpy-win64')
import subprocess
cmd = "adb devices"
device = subprocess.check_output(cmd).decode('utf8').strip().replace("List of devices attached","").strip()[:-7]

client = AdbClient(host="127.0.0.1", port=5037)
device = client.device(device)
device.push("c:\python36\scripts\d123.txt", "/sdcard/Download/d1234.txt")

cmd2 = "adb shell ls /sdcard/Download/d1234.txt"
file_status = subprocess.check_output(cmd2).decode("utf8").strip()
print("the file is here: -->> " + file_status)

from pure-python-adb.

Swind avatar Swind commented on September 17, 2024

Hi selster
You can use this to list all devices and get the serial number.

from adb.client import Client as AdbClient
client = AdbClient(host="127.0.0.1", port=5037)
devices = client.devices()

for device in devices:
    print(device.serial)

from pure-python-adb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.