1

我正在尝试在我的应用程序中向 /system/build.prop 添加一些内容,但我不知道如何通过 ListPreference 更改它。

这就是我的代码现在的样子:

public static class NotificationPreferenceFragment extends PreferenceFragment {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.pref_monitor);

    bindPreferenceSummaryToValue(findPreference("monitor"));

我的 XML 状态:

<ListPreference
        android:key="monitor"
        android:id="@+id/monitor"
        android:title="Select monitor"
        android:defaultValue="1"
        android:entries="@array/monitor_titles"
        android:entryValues="@array/monitor_values"
        android:negativeButtonText="@null"
        android:positiveButtonText="@null" />

数组是:

<string-array name="monitor_titles">
    <item>320</item>
    <item>280</item>
    <item>260</item>
    <item>240</item>
    <item>200</item>
    <item>180</item>
</string-array>
<string-array name="monitor_values">
    <item>320</item>
    <item>280</item>
    <item>260</item>
    <item>240</item>
    <item>200</item>
    <item>180</item>
</string-array>

我可以用按钮毫无问题地做到这一点,例如添加:

try{
    Runtime.getRuntime().exec( new String[] { "su", "-c", "mount -o remount,rw /system" });
    Runtime.getRuntime().exec( new String[] { "su", "-c", "sed -i '/ro.sf.lcd_density=*/d' /system/build.prop"});
    Runtime.getRuntime().exec( new String[] { "su", "-c", "echo ro.sf.lcd_density=320 >> /system/build.prop"});
    Runtime.getRuntime().exec( new String[] { "su", "-c", "sed -i '/ro.sf.lcd_density==320/d' /system/build.prop"});
    Runtime.getRuntime().exec( new String[] { "su", "-c", "mount -o remount,ro /system" });
    Runtime.getRuntime().exec( new String[] { "su", "-c", "killall zygote"});
} catch (IOException e) {
    e.printStackTrace();

}

但是我将如何将它添加到 ListPreference 中?帮助将不胜感激!

4

0 回答 0