Android modify the system default time 12 hours / 24 hours

The code that determines the time format of the system when the android system is turned on for the first time is in the SettingsProvider application of the frameworks layer. 
1. Add the corresponding code in defaults.xml. 
Add a line in the frameworks \ base \ packages \ SettingsProvider \ res \ values ​​\ defaults.xml file

<string name="def_time_12_24" translatable="false">24</string>

Among them, 24 means that the time format is 24 hours. If it is written as 12, it means that the time format is 12 hours. The android system defaults to the 12-hour format.

2. Add the corresponding code in DatabaseHelper.java. Find the loadSystemSettings () function
in the frameworks \ base \ packages \ SettingsProvider \ src \ com \ android \ providers \ settings \ DatabaseHelper.java 
file, add a line in this function

loadStringSetting(stmt, Settings.System.TIME_12_24, R.string.def_time_12_24);


This changes the time format of the Android system to 12 hours to 24 hours. 
Note: Settings.System.TIME_12_24 is
defined in frameworks / base / core / java / android / provider / Settings.java  :

/**
 * Display times as 12 or 24 hours
 *   12
 *   24
 */
public static final String TIME_12_24 = "time_12_24";


It can be seen that the list saved in settings.db is time_12_24.

3. Verification 
There are two verification methods: 
1. After the modification and replacement to Settingprovider.apk, you need to delete this folder under data / data / under com.android.provider.setting. Because there is the previous default data cached in this file.

2. Restore factory settings.

Published 31 original articles · Likes6 · Visitors 10,000+

Guess you like

Origin blog.csdn.net/u012824529/article/details/96306544
Recommended