Skip to content

Instantly share code, notes, and snippets.

@letroll
Last active January 15, 2021 13:27
Show Gist options
  • Save letroll/5ba28378ea22c835936b15cbdd0665f8 to your computer and use it in GitHub Desktop.
Save letroll/5ba28378ea22c835936b15cbdd0665f8 to your computer and use it in GitHub Desktop.
[log sharedpreference] log current application shared preference #android #adb #log #preference
function logPackageName() {
adb shell dumpsys activity recents | grep 'Recent #0' | cut -d= -f2 | sed 's| .*||' | cut -d '/' -f1
}
function logpref() {
APP_ID=$(logPackageName)
echo "current packageName:$APP_ID"
SHARED_PREF_FILES=$(adb shell "run-as $APP_ID ls /data/data/${APP_ID}/shared_prefs/")
SHARED_PREF_FILE=${SHARED_PREF_FILE[0]}
echo "current preference file:$SHARED_PREF_FILE"
echo "content:"
adb shell "run-as $APP_ID cat /data/data/${APP_ID}/shared_prefs/$SHARED_PREF_FILE"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment