redev

technical miscellaneous memorandum

SharedPreferencesとInternal Storage

保存・読み込みが出来るのは分かったが、データの実体がどこにあるのか分からない…。
ファイラーで見ようにも、MODE_PRIVATE にしているから見えないのか?

---
追記(17/01/17)

  • SharedPreferenceの内容の確認

sdk/toolsとsdk/platform-toolsにパスを通し、コマンドプロンプト

> adb shell

とすると実機の中に入れるので

$ run-as (Activityのパッケージ名)

と入力。/data/data/(パッケージ名) のディレクトリに移動できる。

$ ls -l
  :
drwxrwx--x u0_a238  u0_a238           2017-01-17 01:58 shared_prefs

ここにSharedPreferenceの実体がある。このディレクトリに移動すると、(指定したファイル名).xmlがある。catで中身も確認できる。

$ cat hoge.xml
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
    <float name="float" value="3.1415927" />
    <boolean name="boolean" value="true" />
    <long name="long" value="2147483648" />
    <string name="string">蜷榊燕</string>
    <int name="int" value="100" />
</map>
  • InternalStorageの内容の確認

同様にadb shell、run-as…で

$ ls -l
  :
drwxrwx--x u0_a239  u0_a239           2017-01-17 02:02 files

ここにInternalStorageの実体がある。確認方法は前項と同様なので割愛。