Skip to content

Instantly share code, notes, and snippets.

@ashdavies
Last active February 18, 2018 16:06
Show Gist options
  • Save ashdavies/7812583e6bc817effdebc2e4af64b8d2 to your computer and use it in GitHub Desktop.
Save ashdavies/7812583e6bc817effdebc2e4af64b8d2 to your computer and use it in GitHub Desktop.
Save matching APK files from an Android device
#!/bin/sh
if test $# -lt 1; then
echo "usage: apk pattern target_directory"
exit 1
fi
DIR="${2:-$PWD}"
for ENTRY in $(adb shell pm list packages -f | grep $1); do
PACKAGE=$(echo $ENTRY | sed -n 's/package:\(.*\)=.*$/\1/p')
NAME=$(echo $ENTRY | sed -n 's/^.*apk=\(.*\).*$/\1/p')
echo "Saving $PACKAGE to output directory $DIR/$NAME.apk"
adb pull $PACKAGE $DIR/$NAME.apk
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment