Created
April 16, 2013 17:54
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.