9820E平台-Android默认配置24小时制
2019-11-22 本文已影响0人
DD_Dog
修改步骤
Android系统默认是12小时制度的,现将它修改为24小时制。
一、修改默认配置文件
frameworks/base/packages/SettingsProvider/res/values/defaults.xml
添加配置
<string name="time_12_24">24</string>
time_12_24字符串是在SettingsProvide
r目录下Settings.java
中定义的。
二、数据库加载
frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
找到private void loadSystemSettings(SQLiteDatabase db) 方法,在该方法中添加
loadStringSetting(stmt, Settings.System.TIME_12_24, R.string.time_12_24);
三、测试
重新编译mm
,将生成的SettingsProvider.apk安装到测试机
注意,只替换SettingsProvider模块,需要删除旧的数据库,否则数据库不会重新加载!
adb root
adb remount
adb push xxx/SettingsProvider.apk system/priv-app
adb shell
#rm -rf data/data/com.android.providers.settings/databases/
#reboot
测试代码:
String value = Settings.System.getString(context.getContentResolver(),
Settings.System.TIME_12_24);
PS
android数据库中的load字段的方法是类型对应的,defaults.xml中定义的是<string name="time_12_24">24</string>
,这是一个string,就必须调用loadStringSetting
,如果用loadIntSetting的话就加载不到了,显然24和"24"对java来说是一样可以强转的。其他类型也一样,需要一一对应
修改记录
diff --git a/packages/SettingsProvider/res/values/defaults.xml b/packages/SettingsProvider/res/values/defaults.xml
index 4de559e9..3b4185c5 100755
--- a/packages/SettingsProvider/res/values/defaults.xml
+++ b/packages/SettingsProvider/res/values/defaults.xml
@@ -17,6 +17,7 @@
*/
-->
<resources>
+ <string name="time_12_24">24</string>
<bool name="def_dim_screen">true</bool>
<integer name="def_screen_off_timeout">60000</integer>
<integer name="def_button_light_off_timeout">1500</integer>
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
index 88fbce2f..28a294fe 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
@@ -1966,6 +1966,8 @@ public class DatabaseHelper extends SQLiteOpenHelper {
try {
stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
+ " VALUES(?,?);");
+ //set default time foramt--bianjb
+ loadStringSetting(stmt, Settings.System.TIME_12_24, R.string.time_12_24);
loadBooleanSetting(stmt, Settings.System.DIM_SCREEN,
R.bool.def_dim_screen);