J2897

[Android] ADB Install Apps

Mar 29th, 2015
625
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 2.05 KB | None | 0 0
  1. :: Released under the GNU General Public License version 3 by J2897.
  2.  
  3. @echo OFF
  4. setlocal
  5.  
  6. REM Possible locations to find ADB.
  7. set "ADB[1]=C:\Android\adb.exe"
  8. set "ADB[2]=C:\Program Files\Android\android-sdk\platform-tools\adb.exe"
  9. set "ADB[3]=C:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe"
  10.  
  11. REM Find ADB.
  12. if exist "%ADB[1]%" (set "ADB=%ADB[1]%")
  13. if exist "%ADB[2]%" (set "ADB=%ADB[2]%")
  14. if exist "%ADB[3]%" (set "ADB=%ADB[3]%")
  15.  
  16. REM Did we find ADB?
  17. if not defined ADB (
  18.     echo Android Debug Bridge not found. Get it from here...
  19.     echo http://developer.android.com/sdk/index.html
  20.     goto :End
  21. )
  22.  
  23. if [%1]==[] (
  24.     echo Drop some APKs on top of this file to install them on your SD Card.
  25.     goto :End
  26. )
  27.  
  28. REM Start a fresh ADB daemon.
  29. "%ADB%" kill-server
  30. "%ADB%" -d devices -l || goto :End
  31.  
  32. REM Unable to use double-quotes. So prepare to temporarily change directory. It's future-proof this way.
  33. REM If the parentheses in ADB[3] cause problems for 64-Bit users, output and iterate a temporary text file, or change the directory permanently.
  34. for /f "delims=" %%A in ("%ADB%") do (
  35.     set "ADB_FOLDER=%%~dA%%~pA"
  36.     set "ADB_FILE=%%~nA"
  37. )
  38.  
  39. REM Is the device connected?
  40. pushd "%ADB_FOLDER%"
  41. for /f "delims=" %%A in ('%ADB_FILE% -d devices ^| find "" /v /c') do (set "LINE_COUNT=%%A")
  42. popd
  43. if %LINE_COUNT% LSS 3 (
  44.     echo Connect your device via USB and try again.
  45.     goto :End
  46. )
  47.  
  48. :Getfile
  49. echo.
  50. if [%1]==[] (goto :End)
  51. set "FILENAME=%~nx1"
  52.  
  53. REM Check the file extension.
  54. for /f "delims=" %%A in ("%FILENAME%") do (set "EXTENSION=%%~xA")
  55. if /i not "%EXTENSION%"==".apk" (
  56.     echo [%FILENAME%] is not an APK.
  57.     goto :Skip
  58. )
  59.  
  60. echo [%FILENAME%]
  61. set LOCAL="%1"
  62. set REMOTE="/storage/sdcard0/APKs/%FILENAME%"
  63.  
  64. echo Sending the APK to the device...
  65. "%ADB%" -d push %LOCAL% %REMOTE% || goto :Skip
  66.  
  67. echo Installing the app...
  68. "%ADB%" -d shell pm install -s %REMOTE% || goto :Skip
  69.  
  70. echo Removing the APK...
  71. "%ADB%" -d shell rm %REMOTE% || goto :Skip
  72. echo Done.
  73.  
  74. :Skip
  75. shift
  76. goto :Getfile
  77.  
  78. :End
  79. echo.
  80. echo Finished!
  81. echo.
  82. endlocal
  83. pause
Add Comment
Please, Sign In to add comment