I was doing this just now using scrcpy while i didn’t want to connect a cable
if your phone’s android is 11 or greater then
- enable developer options
- enable usb debugging
- enable adb over wifi
- disable adb permissions revoking
- enable usb debugging (security settings)
- and finally connect once via code
also you must have static ip for the phone ,preferably via the router
after all these and if you reboot your phone or disable adb over wifi, you just enable again adb over wifi and note the port your phone is telling you to use (port is different every time you re-enable adb over wifi or reboot)
here is my script to automate the job (change phone’s ip accordingly)
#!/bin/bash
adb kill-server
wait
echo " "
if [ ! -f /tmp/port ]; then
echo What is the phones port?
echo " "
read port
touch /tmp/port
wait
echo $port > /tmp/port
echo " "
fi
read -r port < /tmp/port
wait
adb connect 192.168.1.4:$port
wait
echo " "
if adb get-state 1>/dev/null 2>&1
then
scrcpy -b 2M -m 1070 -S -t -w --window-height 1070 --power-off-on-close --disable-screensaver --tcpip=192.168.1.4:$port
wait
echo " "
adb disconnect 192.168.1.4:$port
wait
echo " "
adb kill-server
wait
exit
else
adb kill-server
wait
echo " "
while [[ -z $(adb get-state) ]]
do
adb kill-server
wait
echo " "
echo What is the phones port?
echo " "
read port
wait
echo $port > /tmp/port
adb connect 192.168.1.4:$port
wait
echo " "
done
scrcpy -b 2M -m 1070 -S -t -w --window-height 1070 --power-off-on-close --disable-screensaver --tcpip=192.168.1.4:$port
wait
echo " "
adb disconnect 192.168.1.4:$port
wait
echo " "
adb kill-server
wait
exit
fi
REMEMBER TO ALWAYS DISABLE ADB OVER WIFI AFTER YOU ARE DONE (to avoid unwanted wireless connections to your phone by others nearby)
scrcpy documentation and switches here