3

I need to run a script in debug mode that will pull all sharedpreferences into a folder. From my research i can only pull from debug builds. I tried from a non-rooted phone to get the sharedpreferences like this:

$adb shell
$adb run-as mypackagename

then i was able to traverse to /data/data/mypackagename/shared_prefs

but i'd like to be able to put this in a script. I can only call adb pull from outside adb shell. how can i get the shared_prefs entire folder pulled out of a normal non-rooted device on a debug application ? there must be a way because how is facebook setho doing it ?

This question is about retrieving sharedPreferences not a database retrieval.

j2emanue
  • 60,549
  • 65
  • 286
  • 456
  • Possible duplicate of [android adb, retrieve database using run-as](http://stackoverflow.com/questions/18471780/android-adb-retrieve-database-using-run-as) – Alex P. Jan 06 '16 at 19:24
  • thats about database, this is sharedpreference. Although slightly similar my question speaks specifically about shared preference retrieval. Some can be in private mode etc. – j2emanue Jan 06 '16 at 19:37

1 Answers1

4

I created the following shell script

#!/bin/bash

pname=$1

if [ -z "${pname}" ]; then
    echo "Please enter a package name"
    exit 1
fi

adb shell "run-as $pname chmod 776 shared_prefs"
adb pull /data/data/$pname/shared_prefs ./${pname}_shared_prefs
adb shell "run-as $pname chmod 771 shared_prefs"

name it pullsharedprefs.sh (or whatever you want) and from terminal run the command:

chmod +x pullsharedprefs.sh
./pullsharedprefs.sh some.package.name

shared_prefs will be pulled to the current working directory and named {package-name}_shared_prefs


Tested using genymotion (Android 5.1.1)

Jared Rummler
  • 37,824
  • 19
  • 133
  • 148
  • When I run this against my device (running Nougat), I see the following error when trying to `pull`: `adb: error: remote object '/data/data//shared_prefs' does not exist` even though I can see and inspect the shared preferences directory if I manually use the device shell. Any ideas why that might be? – stkent Oct 06 '16 at 15:21