这边就上面的知识,进行一个小工具开发。主要实现功能有快速查看设备名、包名和Activity.具体看实现的代码
代码语言:javascript复制#coding:utf-8
from tkinter import *
import tkinter as tk
import os
root = Tk()
root.title('获取APP应用小工具')
# 按扭调用的函数,
def get_devices():
lists = (os.popen('adb devices').read())
devices = (lists.strip().split('n'))
devices_list = []
for i in range(1, len(devices)):
device = (devices[i].split('t')[0])
devices_list.append(device)
if devices_list: # 通过判断列表是否为真(有数据),说明获取设备序列号成功
return devices_list[0]
else:
return "没有发现设备,请检查设备是否连接电脑!"
def get_packy():
# adb shell dumpsys window w |findstr / |findstr name=
zhi = (os.popen('adb shell dumpsys window w |findstr / |findstr name=').read())
d = (zhi.strip().split('n'))
pack = d[0].split('=')[-1]
print(pack)
package = pack.split('/')[0]
# print(package)
return package
def get_activity():
zhi = (os.popen('adb shell dumpsys window w |findstr / |findstr name=').read())
d = (zhi.strip().split('n'))
act = d[0].split('=')[-1]
print(act)
activity = act.split('/')[1]
a = activity.replace(')','')
print(a)
return a
def huoqu_activity():
result3 = get_activity()
print(result3)
v3.set(str(result3))
global root
e3 = tk.Entry(root, text=v3, state="readonly")
e3.pack(side=LEFT)
def huoqu_package():
result2 = get_packy()
print(result2)
v2.set(str(result2))
global root
e2 = tk.Entry(root, text=v2, state="readonly")
e2.pack(side=LEFT)
def huoqu_name():
result = get_devices()
print(result)
v1.set(str(result))
global root
e1 = tk.Entry(root, text=v1, state="readonly")
e1.pack(side=LEFT)
tk.Label(root, text="device_name:").grid(row=0, column=0,sticky=W) # 位于第0行,第0列
tk.Label(root, text="package:").grid(row=1, column=0, sticky=W) # 位于第1行,第0列
tk.Label(root, text="Activity:").grid(row=2, column=0, sticky=W) # 位于第1行,第0列
v1 = tk.StringVar()
v2 = tk.StringVar()
v3 = tk.StringVar()
e1 = tk.Entry(root, textvariable=v1, state="readonly", width=50)
e2 = tk.Entry(root, textvariable=v2, state="readonly", width=50)
e3 = tk.Entry(root, textvariable=v3, state="readonly", width=50)
e1.grid(row=0, column=1, padx=10, pady=5) # 位于第0行,第1列
e2.grid(row=1, column=1, padx=10, pady=5) # 位于第1行,第1列
e3.grid(row=2, column=1, padx=10, pady=5) # 位于第1行,第1列
# 第三行登陆按扭,command绑定事件
B_1 = Button(root, text='获取设备名称', command=huoqu_name).grid(row=0,column=2,sticky=tk.E)
B_2 = Button(root, text='获取包名', command=huoqu_package).grid(row=1,column=2,sticky=tk.E)
B_3 = Button(root, text='获取Activity', command=huoqu_activity).grid(row=2,column=2,sticky=tk.E)
# b_login = Button(root, text='获取设备信息', command=huoqu_name)
# b_login.grid(row=3, column=1, sticky=E)
tk.Button(root,text="退出", command=root.quit)
.grid(row=3,column=2,sticky = tk.E)
root.mainloop()
运行结果