'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?



Solution 1:[1]

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

https://github.com/jfsso/PreferencesEditor

Solution 2:[2]

This usage from https://github.com/jfsso/PreferencesEditor does not work for all apps. You can change another app's shared preference this way only if it integrates the instrument from that repository.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jimbr
Solution 2 Tuff Contender