读书人

读写系统设立

发布时间: 2012-10-14 14:55:07 作者: rapoo

读写系统设置
Android的很多设置想关的东西都存储在数据库中
android的Settings.System.java中设置了很多相关属性
例如:

        /**         * Value to specify if the user prefers the date, time and time zone         * to be automatically fetched from the network (NITZ). 1=yes, 0=no         */        public static final String AUTO_TIME = "auto_time";        /**         * Display times as 12 or 24 hours         *   12         *   24         */        public static final String TIME_12_24 = "time_12_24";        /**         * Date format string         *   mm/dd/yyyy         *   dd/mm/yyyy         *   yyyy/mm/dd         */        public static final String DATE_FORMAT = "date_format";

等等好多好多变量,每个变量想当于数据库表的字段名,如果要读写字段的值可以通过put**(), get**()方式。

例如读取value为int型的值:
//取  public static int getInt(ContentResolver cr, String name, int def);  public static int getInt(ContentResolver cr, String name);  //写   public static boolean putInt(ContentResolver cr, String name, int value);


以此类推读取String Boolean long float等类型的值就用
getString(...),getLong(...),getFloat(...);
putString(...),puLongt(),putFloat(...);


public static Uri getUriFor(String name)
System.java还提供了一个方法(getUriFor(String name)
)可以通过它得知每个变量的URI,拿到了这个URI就可以自己访问数据库,自己读写系统自带的配置参数。

但是切记:改写Seting的值必须要在AndroidManifest.xml中添加权限:
<uses-permission android:name = "android.permission.WRITE_SETTINGS"/>

读书人网 >其他相关

热点推荐