说明:
最近碰到一个需求,adb连接手机,然后用adb命令安装apk,并且自动打开
(1)新建ip.txt文件,写入手机的ip:
192.168.1.63
(2)将打包生成好的apk,跟ip.txt放在同一文件夹内,记录好apk名称和apk包名
(3)新建install.txt文件,写入指令,保存在跟ip.txt放在同一文件夹内
@echo off
setlocal enabledelayedexpansion
adb disconnect
for /f %%a in (ip.txt) do (
echo %%a
adb connect %%a
for /F "delims=" %%d in ('adb shell cat /sys/class/net/eth0/address') do (
set macs=%%d
echo %%d ---
)
echo %%a -- mac------:!macs!
if "!macs!"=="" (
echo %%a mac is null !! error exit!!
goto end
)
echo replace result is !macs::=-!
adb uninstall com.example.musicpath
adb install musicpath.apk
adb shell am start -n com.example.musicpath/.MainActivity
ping %%a -n 2 >nul
adb shell input tap 1190 570
ping %%a -n 2 >nul
adb shell input tap 1186 574
ping %%a -n 2 >nul
adb shell input tap 950 675
echo "%%a --------------> disconnect"
adb disconnect
)
:end
pause
(4)修改install.txt文件后缀,改为install.bat
(5)双击运行install.bat,等待安装完成
end