If you have multiple Android devices (including Android emulators) connected to your PC, you will need to use the Adb-s DeviceID shell when you enter the console. More trouble, this article has written a shell script file (need to be used under Linux or OS X, Windows needs to be newly written with bat or cmd).
The basic idea is to use the ADB devices command to scan how many Android devices are connected to the PC, then intercept the device name from the return value and display a menu. Finally, the user can select the sequence number in front of the menu item to enter the specified Android device. No more input DeviceID.
The effect is as shown.
common.sh
Selected_device=""#"": No Android device availablefunctionfind_devices () {device_list=$ (ADB devices)if["${device_list:0:4}"!="List"]; Thendevice_list=$ (ADB devices)if["${device_list:0:4}"!="List"]; ThenExitfi fivalue=$(Echo$device _list |Cut-D' '-f5)if["$value"==""]; Then Echo "no Android devices available" ElseSelected_device=$value # Assume that there are only 1 devices of value=$(Echo$device _list |Cut-D' '-F7) # Multiple devicesif["$value"!=""]; ThenI=5Index=1value="~~~" Echo "List of available devices" while[""=="" ] Dovalue=$(Echo$device _list |Cut-D' '-f$i) let"i= $i +2" if["$value"==""]; ThenBreak ; fi Echo "$index: $value" Let"index= $index +1" DoneRead-P"which Android device do you want to choose? Please enter the serial number (1):" Numberif["$number"==""]; Then Number=1 fi Let"number=3 + $number * 2"Selected_device=$(Echo$device _list |Cut-D' '-f$number) # Gets the device ID based on the device index selected by the userfi fi}
shell.sh
Source Common. SH find_devices if " $selected _device " "" Then -S $selected _device Shell $1fi
You need to put the common.sh and shell.sh files in the same directory and execute the shell.sh (you need to set their executable permissions using the chmod command)
This script is provided by Android in- depth exploration of volume 1:hal and drive development .
can display the Android device selection list and enter the shell script for the specified Android device console