Untitled
unknown
plain_text
a year ago
3.4 kB
8
Indexable
import tkinter as tk
from tkinter import messagebox
import subprocess
import time
# 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
# 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ị.")
# Chụp ảnh màn hình từ thiết bị Android và lưu trên điện thoại
def take_screenshot(device_id):
try:
# Tạo timestamp cho tên file giống như hệ thống Android
timestamp = time.strftime("%Y%m%d_%H%M%S")
screenshot_file = f"/sdcard/Pictures/Screenshots/Screenshot_{timestamp}.png"
# Chụp ảnh màn hình và lưu trên điện thoại
result = subprocess.run(["adb", "-s", device_id, "shell", "screencap", "-p", screenshot_file], 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"Đã lưu ảnh màn hình trên thiết bị {device_id}: {screenshot_file}")
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 và lưu trên điện thoạ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)
# Chạy ứng dụng
root.mainloop()Editor is loading...
Leave a Comment