修改当前连接设备方法

This commit is contained in:
zyj
2025-10-29 18:31:18 +08:00
parent 180b51267d
commit a03d13613c
4 changed files with 821 additions and 1 deletions

View File

@@ -1,5 +1,45 @@
package main
func main() {
import (
"fmt"
"go-mobile-uiautomator/adb"
"time"
)
func main() {
// edit these for your environment
addr := "127.0.0.1:5037"
local := "C:/Users/01/Desktop/aaa.PNG"
remote := "/sdcard/aaa.PNG"
mode := 0644
// targetProduct := "23113RKC6C"
adb.SyncPushTryVariants(addr, "emulator-5554", local, remote, mode, true)
}
// 连接验证
func Connect() {
addr := "127.0.0.1:5037"
targetProduct := "23113RKC6C"
serial, err := adb.FindSerialByProduct(addr, targetProduct)
if err != nil {
fmt.Println("find device error:", err)
return
}
fmt.Println("found serial:", serial)
// Now open a new connection and transport to the found device for further ops
conn, err := adb.DialADB(addr, 15*time.Second)
if err != nil {
fmt.Println("dial error:", err)
return
}
defer conn.Close()
adb.TransportTo(conn, serial)
out, err := adb.ExecShell(conn, "getprop")
if err != nil {
fmt.Println("shell error:", err)
} else {
fmt.Printf("shell out: %q\n", string(out))
}
}