Settings.System的使用
2012-05-17 19:27 htc开发 阅读(917) 评论(0) 编辑 收藏 举报
那通过数据库来保存就会有Provider了,所以就会有SettingsProvider了。数据库的路径就是:/data/data/com.android.providers.settings/databases/settings.db
但我们平常获取这里面的数据不是直接通过ContentResolve而是android已经封装了一层,通过Settings这个类来获取,就像MediaStore一样。
比如我们获取飞行模式:
通过name,查询数据库,获取你想要的值,如果没有取到,就默认为def.否则就是其返回的值
public static int getInt (ContentResolver cr, String name, int def)
Since: API Level 3Convenience function for retrieving a single secure settings value as an integer. Note that internally setting values are always stored as strings; this function converts the string to an integer for you. The default value will be returned if the setting is not defined or not an integer.
Parameters
cr | The ContentResolver to access. |
---|---|
name | The name of the setting to retrieve. |
def | Value to return if the setting is not defined. |
Returns
- The setting's current value, or 'def' if it is not defined or not a valid integer.
public static boolean putInt (ContentResolver cr, String name, int value)
Since: API Level 3Convenience function for updating a single settings value as an integer. This will either create a new entry in the table if the given name does not exist, or modify the value of the existing row with that name. Note that internally setting values are always stored as strings, so this function converts the given value to a string before storing it.
Parameters
cr | The ContentResolver to access. |
---|---|
name | The name of the setting to modify. |
value | The new value for the setting. |
Returns
- true if the value was set, false on database errors