can display the Android device selection list and enter the shell script for the specified Android device console

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.