How To Connect to adb via WiFi *With a convenient BAT file*

你离开我真会死。 提交于 2019-12-13 18:22:25

问题


I was trying to find a way to connect Via WiFi to my android.. Found some on StackOverflow but they were all requireing going to cmd every time I wanted to connect my android.. So I came up with a bat file

See below


回答1:


I Found some nice ways to connect to your device via WiFi on Stackoverflow.. But they all required going to cmd every time you wanted to connect and this was inconvenient for me..

So I spent some time and created a bat file which with one click allows you to connect your android to adb via WiFI

All you need to do is set defaultIp AND adbLoc to the IP of the device and adbLoc to the location of your adb (sdk\platform-tools)

TO USE THIS YOU MUST INITIALLY HAVE YOUR ANDROID CONNECTED VIA USB

well I had to...

NOTE

Your android must be connected Via USB initially to connect using TCP/IP My test was done and a Galaxy Tab 2 10.1 non rooted I also added an exception to my firewall for port 5555

Declatations:

defaultIp                 == the IP of your android
adbLoc                    == where the adb.exe is located for the sdk
enableSetVariablesWarning == Show the initial warning?
askForIP                  == If your android has a dynamic ip you might have
...                          to set this to true, else set to false

The Actual Bat file (save this as startAdbWifi.bat where ever, like desktop)

@echo off

:: This is one of my First bat's so sorry if it's terrible

:: Initilisation of Variables.. Put your defualts in here
:: Change enableSetVariablesWarning to anything else to
:: disable warning
set defaultIp="SET ME"
set adbLoc="SET ME"
set enableSetVariablesWarning="true"
set askForIP="true"
:: End of Initiation

if /I %enableSetVariablesWarning%=="true" GOTO COMMENT
GOTO ENDOFCOMMENTS
:COMMENT
@echo 01010101010101010101010101 CONFIG 01010101010101010101010101
@echo Is This your first time using this bat?
@echo make sure that you have configured:
@echo defaultIp: %defaultIp%
@echo adbLoc: %adbLoc%
@echo askForIP: %askForIP%
@echo change "enableSetVariablesWarning" to anything other than
@echo true to disable this warning
@echo 01010101010101010101010101 CONFIG 01010101010101010101010101
@echo.
:ENDOFCOMMENTS

@echo Make sure that the Android is connected

if /I %askForIP%=="true" GOTO GETIP
set ip=%defaultIp%
GOTO CONNECT

:GETIP
set ip="invalid"
set /p ip="Enter IP(default=192.168.1.75): " %=%
if /I %ip%=="invalid" GOTO SETIP
GOTO CONNECT
:SETIP
set ip=%defaultIp%
@echo Defaulting the ip to: %ip%


:CONNECT
set curr_dir=%cd%

chdir /D %adbLoc%
@echo Restarting adb
adb kill-server


adb tcpip 5555
adb connect %ip%
adb devices
chdir /D %curr_dir%

set /p ip="Press Enter to Exit" %=%

Sorry if the bat is terrible, one of my first



来源:https://stackoverflow.com/questions/16810593/how-to-connect-to-adb-via-wifi-with-a-convenient-bat-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!