【问题标题】:Modify xml shared_prefs file using adb使用 adb 修改 xml shared_prefs 文件
【发布时间】:2020-11-11 09:12:03
【问题描述】:

我正在尝试使用 adb 与 android 应用 shared_prefs 进行交互。

让我们在这个例子中使用 VLC。 共享首选项存储在:/data/data/org.videolan.vlc/shared_prefs/org.videolan.vlc_preferences.xml

文件示例是:

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

据此:

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

我应该能够做到:

# 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

这和变体不起作用。我想我可能不正确地处理地图。请问有什么建议吗?

【问题讨论】:

    标签: android shell sharedpreferences adb


    【解决方案1】:

    我也看到了那个备忘单。我认为这取决于:

    https://github.com/jfsso/PreferencesEditor

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-28
      相关资源
      最近更新 更多