Created
March 25, 2024 14:53
-
-
Save yuceltoluyag/86843d19925920d169548be0cd4c5034 to your computer and use it in GitHub Desktop.
Terminal & Windows command to get Android device name along with AVD name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
from ppadb.client import Client as AdbClient | |
class EmulatorDetector: | |
def __init__(self, emulator_executables): | |
self.emulator_executables = emulator_executables | |
def find_emulator(self): | |
try: | |
# PowerShell komutu ile görev yöneticisinde çalışan uygulamaları listeleme | |
powershell_command = ( | |
"Get-Process | Select-Object -ExpandProperty ProcessName" | |
) | |
output = subprocess.check_output( | |
["powershell", "-Command", powershell_command], text=True | |
) | |
# Görev yöneticisindeki uygulamaları kontrol ederek emülatörü tespit etme | |
for emulator, executables in self.emulator_executables.items(): | |
for executable in executables: | |
if executable.lower() in output.lower(): | |
return emulator | |
return "Emulator not found" | |
except subprocess.CalledProcessError: | |
return "Error occurred" | |
class DeviceDetailsGetter: | |
def __init__(self, host="127.0.0.1", port=5037): | |
self.host = host | |
self.port = port | |
def get_details(self): | |
client = AdbClient(host=self.host, port=self.port) | |
devices = client.devices() | |
details = [] | |
for device in devices: | |
details.append( | |
{ | |
"Serial": device.serial, | |
"Name": device.get_properties().get("ro.product.name", "Unknown"), | |
"Model": device.get_properties().get("ro.product.model", "Unknown"), | |
"Manufacturer": device.get_properties().get( | |
"ro.product.manufacturer", "Unknown" | |
), | |
} | |
) | |
return details | |
def main(): | |
emulator_executables = { | |
"BlueStacks": ["HD-Player", "BlueStacks"], | |
"LDPlayer": ["dnplayer"], | |
"MEmu": ["MEmu"], | |
} | |
emulator_detector = EmulatorDetector(emulator_executables) | |
emulator_name = emulator_detector.find_emulator() | |
print("Emulator:", emulator_name) | |
device_details_getter = DeviceDetailsGetter() | |
device_details = device_details_getter.get_details() | |
for device in device_details: | |
print("Serial:", device["Serial"]) | |
print("Name:", device["Name"]) | |
print("Model:", device["Model"]) | |
print("Manufacturer:", device["Manufacturer"]) | |
print("-" * 20) | |
if __name__ == "__main__": | |
main() | |
# output | |
""" | |
python .\getInfo.py | |
Emulator: LDPlayer | |
Serial: emulator-5554 | |
Name: ASUS_Z01QD | |
Model: ASUS_Z01QD | |
Manufacturer: asus | |
-------------------- | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment