Skip to content

Instantly share code, notes, and snippets.

@johnjohndoe
Created April 16, 2013 17:54
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save johnjohndoe/5398030 to your computer and use it in GitHub Desktop.
Save johnjohndoe/5398030 to your computer and use it in GitHub Desktop.
Shell script which checks if any Android device is connected. I execute this script before processing a Maven project in order to save time when the device has fallen asleep.
#!/bin/bash
check-for-android-device() {
ADB_PATH="${ANDROID_HOME}/platform-tools"
NOT_PRESENT="List of devices attached"
ADB_FOUND=`${ADB_PATH}/adb devices | tail -2 | head -1 | cut -f 1 | sed 's/ *$//g'`
if [[ ${ADB_FOUND} == ${NOT_PRESENT} ]]; then
echo "Android device seems to be missing."
return 1
else
echo "Android device found."
return 0
fi
}
Copy link

ghost commented Oct 7, 2015

Hi @john
It is not correct for some case.
You can try adb kill-server then adb start-server command.

Some time although it seems already connected but can not get deviceID
Terminal only show " List of devices attached"
(If this case occurred , there is only way to resolve by plug in/ plug out cable again. Its my idea)

For the correctly message that make sure it has been connected. It should be shown as :
List of devices attached
xxxxyyyy device

My case that's mean although your function is passed but device still does not connect to PC.
Could you please review your function again? It is helpful for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment