// C# 使用cmd.exe調用adb.exe 直接進入設備shell內
int devicesCount = 0; // 自行獲取 string devicesName = "";// 自行獲取 if (devicesCount > 0) { Process p = new Process(); p.StartInfo.FileName = "cmd"; //設定程序名 p.StartInfo.Arguments = $"/K adb -s {devicesName} shell"; //設定程序執行參數 Console.WriteLine(p.StartInfo.Arguments); p.Start(); }
adb獲取設備信息:
- 進入指定設備
adb -s deriveName shell (一般用在多台設備時, 操作指定設備使用)
- 查看版本 adb version
- 查看日志 adb
logcat
- 查看設備 adb
devices
不進入shell內部操作設備內部 :
- 創建設備內文件夾 adb shell mkdir path
- 獲取設備指定文件內信息 adb shell ls
- 刪除指定文件內文件以及文件夾 adb shell rm -f path (此操作不可逆, 慎重)
- 獲取設備當前路徑 adb shell pwd
- 刪除sdcard/A.txt adb shell rm /sdcard/A.txt
刪除文件夾及其下面所有文件 adb shell rm -r path
- 電腦推送到手機 adb push local remote
- 手機拉取到電腦 adb pull remote local
(Ps:
adb push D:\localtest\ /remotetest/ 推送到遠端時路徑為/remotetest/localtest/....文件夾,
adb push D:\localtest\. /remotetest/ 遠端路徑為/remotetest/....)