The Android device selection list is displayed, and the Shell script of the specified Android device Console is displayed.

Source: Internet
Author: User

The Android device selection list is displayed, and the Shell script of the specified Android device Console is displayed.

If a PC is connected to multiple Android devices (including Android simulators), you must use adb-s deviceid shell when entering the Console. This article has compiled a Shell script file (which can be used in Linux or OS X, and bat or cmd in windows ).
First, use the adb devices command to scan how many Android devices are connected to the PC. Then, extract the device name from the returned value and display a menu. Finally, you can select the serial number before the menu item to enter the specified Android device. You do not need to enter the deviceid.

Shows the effect.

Common. sh

Selected_device = "" # "": no available Android device function find_devices () {device_list = $ (adb devices) if ["$ {device_list: 0: 4 }"! = "List"]; then device_list = $ (adb devices) if ["$ {device_list: 0: 4 }"! = "List"]; then exit fi value = $ (echo $ device_list | cut-d ''-f5) if [" $ value "=" "]; then echo "no available Android device" else selected_device = $ value # assume that only one device has value =$ (echo $ device_list | cut-d'-f7) # multiple devices if ["$ value "! = ""]; Then I = 5 index = 1 value = "~~~ "Echo" list of available devices "while [" "=" "] do value = $ (echo $ device_list | cut-d'-f $ I) let "I = $ I + 2" if ["$ value" = ""]; then break; fi echo "$ index: $ value "let" index = $ index + 1 "done read-p" which Android device do you want to choose? Enter the serial number (1): "number if [" $ number "=" "]; then number = 1 fi let "number = 3 + $ number * 2" selected_device = $ (echo $ device_list | cut-d ''-f $ number) # retrieve the device ID fi Based on the device index selected by the user}

 

Shell. sh

source common.shfind_devicesif [ "$selected_device" != "" ]; then        adb -s $selected_device shell $1fi

You need to put the common. sh and shell. sh files in the same directory, and then execute shell. sh (you need to use the chmod command to set the executable permissions)

This script is provided by "Android Deep Exploration Volume 1: HAL and driver development.

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.