Untitled
unknown
plain_text
a year ago
3.9 kB
11
Indexable
import tkinter as tk
from tkinter import messagebox
import subprocess
# Lấy danh sách thiết bị đã kết nối qua ADB
def get_connected_devices():
result = subprocess.run(["adb", "devices"], stdout=subprocess.PIPE)
devices = result.stdout.decode().splitlines()[1:] # Bỏ dòng tiêu đề 'List of devices attached'
device_list = [line.split()[0] for line in devices if "device" in line]
return device_list
# Hiển thị danh sách thiết bị kết nối
def display_connected_devices():
devices = get_connected_devices()
device_listbox.delete(0, tk.END) # Xóa danh sách cũ
if devices:
for device in devices:
device_listbox.insert(tk.END, device) # Thêm từng thiết bị vào Listbox
else:
device_listbox.insert(tk.END, "Không có thiết bị nào được kết nối.")
# Mở Chrome và truy cập URL trên thiết bị Android
def open_link_on_device(device_id, url):
subprocess.run(["adb", "-s", device_id, "shell", "am", "start", "-a", "android.intent.action.VIEW", "-d", url])
# Mở link trên tất cả các thiết bị đã kết nối
def open_link_on_all_devices():
url = url_entry.get()
if not url:
messagebox.showwarning("Cảnh báo", "Vui lòng nhập URL.")
return
devices = get_connected_devices()
if not devices:
messagebox.showerror("Lỗi", "Không tìm thấy thiết bị Android nào được kết nối.")
return
for device in devices:
print(f"Mở link trên thiết bị {device}...")
open_link_on_device(device, url)
messagebox.showinfo("Thành công", f"Đã mở link trên {len(devices)} thiết bị.")
# Giả lập thao tác chụp màn hình trên thiết bị Android
def take_screenshot(device_id):
try:
# Gửi lệnh ADB để giả lập thao tác chụp màn hình
result = subprocess.run(["adb", "-s", device_id, "shell", "input", "keyevent", "120"], capture_output=True, text=True)
if result.returncode != 0:
print(f"Lỗi khi chụp ảnh màn hình trên thiết bị {device_id}: {result.stderr}")
return
print(f"Đã chụp ảnh màn hình trên thiết bị {device_id}.")
except Exception as e:
print(f"Có lỗi xảy ra: {e}")
# Chụp ảnh màn hình trên tất cả các thiết bị đã kết nối
def take_screenshots():
devices = get_connected_devices()
if not devices:
messagebox.showerror("Lỗi", "Không tìm thấy thiết bị Android nào được kết nối.")
return
for device in devices:
print(f"Chụp ảnh màn hình từ thiết bị {device}...")
take_screenshot(device)
messagebox.showinfo("Thành công", f"Đã chụp ảnh màn hình từ {len(devices)} thiết bị.")
# Giao diện người dùng
root = tk.Tk()
root.title("Chụp ảnh màn hình và mở link trên Android")
# Nhãn và ô nhập URL
url_label = tk.Label(root, text="Nhập URL:")
url_label.pack(padx=10, pady=5)
url_entry = tk.Entry(root, width=50)
url_entry.pack(padx=10, pady=5)
# Nút Mở Link
getlink_button = tk.Button(root, text="Mở Link", command=open_link_on_all_devices)
getlink_button.pack(padx=10, pady=5)
# Nút Chụp Ảnh Màn Hình
capture_button = tk.Button(root, text="Chụp Ảnh Màn Hình", command=take_screenshots)
capture_button.pack(padx=10, pady=5)
# Nút Hiển thị danh sách thiết bị kết nối
refresh_button = tk.Button(root, text="Hiển thị danh sách thiết bị", command=display_connected_devices)
refresh_button.pack(padx=10, pady=5)
# Listbox để hiển thị danh sách thiết bị đã kết nối
device_listbox = tk.Listbox(root, width=50, height=10)
device_listbox.pack(padx=10, pady=5)
# Chạy ứng dụng
root.mainloop()Editor is loading...
Leave a Comment