Create a gist now

Instantly share code, notes, and snippets.

Lists connected Android devices (via adb) and the device's corresponding model and OS version - See http://dallasgutauckis.com/2014/04/09/listing-connected-android-devices-with-os-version-and-model/
#!/bin/bash
if [[ ! $PATH_TO_ADB ]]; then
PATH_TO_ADB=`which adb`
fi
if [[ ! $PATH_TO_ADB ]]; then
if [[ ! $ANDROID_HOME ]]; then
echo "Failed to determine path to adb; consider setting ANDROID_HOME to your SDK directory or PATH_TO_ADB to the path to ADB"
exit 1
fi
PATH_TO_ADB="$ANDROID_HOME/platform-tools/adb"
fi
devices=`$PATH_TO_ADB devices | grep -E "device\$" | cut -f1`
for device in $devices; do
model=$($PATH_TO_ADB -s $device shell getprop ro.product.model | tr -d '\r')
version=$($PATH_TO_ADB -s $device shell getprop ro.build.version.release | tr -d '\r')
printf '%-20s [%6s]: %-20s \n' "$device" "$version" "$model"
done
@SimonMarquis

It's sometimes convenient to have both version name and version code (aka API lvl).

sdk=$($PATH_TO_ADB -s $device shell getprop ro.build.version.sdk | tr -d '\r')
printf '%-20s [%5s ~ %2s]: %-20s \n' "$device" "$version" "$sdk" "$model"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment