Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify xml shared_prefs file using adb

I am trying to interact with android app shared_prefs using adb.

Let's use VLC for this example. The shared preferences are stored in: /data/data/org.videolan.vlc/shared_prefs/org.videolan.vlc_preferences.xml

File example is:

<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
    <string name="app_theme">1</string>
    <boolean name="VideoPaused" value="true" />
    <float name="VideoSpeed" value="1.0" />
    <string name="media_list">file:////sdcard/ssds/Go.mkv</string>
    <long name="position_in_media" value="0" />
    <string name="current_media">file:////sdcard/ssds/Go.mkv</string>
    <int name="current_settings_version" value="1" />
    <boolean name="media_shuffling" value="false" />
    <long name="VideoResumeTime" value="0" />
    <int name="position_in_media_list" value="0" />
</map>

According to this:

--------------------------------------------------------------------------------
Shared Preferences

# replace org.example.app with your application id

# Add a value to default shared preferences.
adb shell 'am broadcast -a org.example.app.sp.PUT --es key key_name --es value "hello world!"'

# Remove a value to default shared preferences.
adb shell 'am broadcast -a org.example.app.sp.REMOVE --es key key_name'

# Clear all default shared preferences.
adb shell 'am broadcast -a org.example.app.sp.CLEAR --es key key_name'

# It's also possible to specify shared preferences file.
adb shell 'am broadcast -a org.example.app.sp.PUT --es name Game --es key level --ei value 10'

# Data types
adb shell 'am broadcast -a org.example.app.sp.PUT --es key string --es value "hello world!"'
adb shell 'am broadcast -a org.example.app.sp.PUT --es key boolean --ez value true'
adb shell 'am broadcast -a org.example.app.sp.PUT --es key float --ef value 3.14159'
adb shell 'am broadcast -a org.example.app.sp.PUT --es key int --ei value 2015'
adb shell 'am broadcast -a org.example.app.sp.PUT --es key long --el value 9223372036854775807'

# Restart application process after making changes
adb shell 'am broadcast -a org.example.app.sp.CLEAR --ez restart true'
-------------------------------------------------------------------------------

I should be able to do something like:

# remove entry position_in_media_list
adb shell am broadcast -a org.videolan.vlc.sp.remove --es map position_in_media_list

# add int entry
adb shell am broadcast -a org.videolan.vlc.sp.PUT --es key bob --ei value 2000
adb shell am broadcast -a org.videolan.vlc.sp.PUT --es map bob --ei value 2000

This and variations does not work. I think I may be handling the map incorrectly. Any suggestions please?

like image 617
Franck E Avatar asked Oct 25 '25 17:10

Franck E


1 Answers

I came across that cheat sheet as well. I think it depends on this:

https://github.com/jfsso/PreferencesEditor

like image 62
jimbr Avatar answered Oct 28 '25 09:10

jimbr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!