2012-09-14
安裝android apk檔案用bat
:: 請將此篇文章所有內容複製到記事本 並將副檔名改成bat後即可使用
:: 使用此檔案的前提
:: 1.要安裝android sdk
:: 2.有安裝對應android裝置的驅動,例:HTC需要安裝HTC Sync
@echo off
:: Install
:: 設定android sdk 路徑
SET ANDROID_SDK_PATH=D:\Android\Sdk
::設定安裝項目
SET INSTALLER=%1
if not defined INSTALLER goto failedCheckPath
:: 先檢查 是否是apk
FOR /F "TOKENS=1 DELIMS=" %%A IN ('"echo %INSTALLER% |find /I ".apk""') DO SET check=%%A
if defined check goto onInstallAndroid
:: 再檢查 是否是ipa
FOR /F "TOKENS=1 DELIMS=" %%A IN ('"echo %INSTALLER% |find /I ".ipa""') DO SET check=%%A
if defined check goto onInstallIOS
:: 都不是 安裝失敗
if not defined check goto failedCheckExtType
:: android 裝置安裝
:onInstallAndroid
for /f "tokens=2 delims=," %%I in (
'wmic process where "name='adb.exe'" get ExecutablePath^,Handle /format:csv ^| find /i "adb.exe"'
) do set "ADB_PATH=%%~I"
if not defined ADB_PATH SET ADB_PATH=%ANDROID_SDK_PATH%\platform-tools\adb.exe
if not exist "%ADB_PATH%" goto failedSDKSetting
set COUNTER=0
echo.
echo 搜尋可用裝置:
::"%ADB_PATH%" devices -l
FOR /F "usebackq skip=1 tokens=1,6 delims=: " %%A IN (`"%ADB_PATH%" devices -l`) DO CALL :get_device %%B %%A
goto get_device_end
:get_device
set /A COUNTER=%COUNTER%+1
@echo [%COUNTER%] %1 %2
set DEVICE_LIST[%COUNTER%]=%2
set MODEL_LIST[%COUNTER%]=%1
goto :eof
:get_device_end
echo.
set C=1
if "%COUNTER%"=="0" goto no_device
if "%COUNTER%"=="1" goto select_device
echo 發現多個裝置
set /P C=[Choice]:
:select_device
@echo off &setlocal
echo 選擇裝置為
set str=DEVICE_LIST[%C%]
call set DEVICE=%%%str%%%
set str=MODEL_LIST[%C%]
call set MODEL=%%%str%%%
echo DEVICE = %DEVICE% MODEL = %MODEL%
if "%DEVICE%"=="" goto no_device
goto install_APK
:no_device
echo 無可用裝置
goto failedInstallAPK
:install_APK
echo.
echo 安裝APK:
echo ===%INSTALLER%===
echo.
"%ADB_PATH%" -s %DEVICE% install -r %INSTALLER%
echo.
if errorlevel 1 goto failedInstallAPK
echo.
echo 安裝完畢
echo.
goto end
:: iOS 裝置安裝
:onInstallIOS
echo.
echo 尚未支援
echo.
goto end
:failedInstallIPA
echo.
echo 安裝IPA失敗
echo.
goto pauseEND
:failedInstallAPK
echo.
echo 安裝APK失敗
echo 請確認是否有連接至少一個android裝置
echo apk檔名包含中文可能出錯
echo.
goto pauseEND
:failedCheckPath
echo.
echo 請將需要安裝的檔案托移至此檔案
echo.
goto pauseEND
:failedCheckExtType
echo.
echo 放置檔案格式不對,請放置 APK 檔
echo.
goto pauseEND
:failedSDKSetting
echo.
echo 環境參數設置錯誤
echo.
goto pauseEND
:pauseEND
pause
exit
:end
timeout 30
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言