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.



The source code is as follows:

common.sh file

Selected_device= "#": No available Android device function find_devices () {device_list=$ (ADB devices) if ["${device_lis T:0:4} "! =" List "]; Then device_list=$ (ADB devices) # Gets the device list if ["${device_list:0:4}"! = "List"]; Thenexit fi fivalue=$ (echo $device _list | cut-d "-f5) if [" $value "= =" "]; Then # no devices available echo "No Android device available" Else selected_device= $value # assume only 1 devices value=$ (echo $device _lis T | Cut-d '-f7) # Multiple devices if ["$value"! = ""];  Then i=5 index=1 value= "~ ~ ~" echo "Available devices list" while ["" = = ""] do # Start display device menu value=$ (echo $device _list | cut-d "-f$i) let" i= $i +2 "If [" $value "= =" "];  Then break; Fi echo "$index: $value" let "index= $index +1" do read-p "which Android device do you want to select? Please enter the serial number (1): "If [" $number "= =" "]; Then number=1 fi let "number=3 + $number * 2" selected_device=$ (echo $device _list | cut-d "-f$numbe R  # Obtain device identification according to user-selected device Fifi} 

shell.sh

SOURCE Common.shfind_devicesif ["$selected _device"! = ""]; Then        adb-s $selected _device Shell    to enter CONSOLEFI based on the device selected by the user


You need to put shell.sh and common.sh in the same directory, and then execute the shell.sh script file (don't forget to use the chmod command to set its executable permissions)

This script is created by"Android in-depth exploration of volume 1:hal and drive development"provided.

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.