[Python] 纯文本查看 # !/usr/bin/python
# -*- coding:utf-8 -*-
import os
runapp_name = "com.tencent.mobileqq/.activity.SplashActivity"
def getDevicesAll():
#获取所有的设备列表
devices = []
try:
for dName_ in os.popen("adb devices"):
if "\t" in dName_:
if dName_.find("emulator") <0:
devices.append(dName_.split("\t")[0])
devices.sort(cmp&#61;None, key&#61;None, reverse&#61;False)
except:
pass
print("设备名称: %s 总数量:%s台" % (devices, len(devices)))
return devices
def find_top_app(devices):
# 循环输入顶层应用
for dName in devices:
try:
out &#61; os.popen(&#39;adb shell "dumpsys activity | grep "mFocusedActivity""&#39;).read()
print(dName&#43;"的当前顶层应用是&#xff1a;"&#43;out)
except:
print(dName &#43; "关闭失败")
def runtest(devices):
# 打开应用
for dName in devices:
try:
os.popen("adb -s " &#43; dName &#43;" shell am start -n "&#43;runapp_name)
print("启动成功")
except:
print(dName&#43;"打开失败")
if __name__&#61;&#61;"__main__":
while True:
try:
devices &#61; getDevicesAll()
except:
print("获取设备出错")
res &#61; input("输入1查看当前的顶层app;2启动qq:")
if int(res)&#61;&#61;1:
try:
find_top_app(devices)
except:
print("启动错误")
elif int(res)&#61;&#61;2:
try:
runtest(devices)
except:
print("启动错误")