Android SystemProperties和Settings.System介绍(转自http://www.linuxidc.com/Linux/2011-08/40887.htm)
2013-01-06 10:21
609 查看
Android SystemProperties和Settings.System介绍,不同应用间传递信息
1 使用 SystemProperties.get
这中方法在framework里面 经常见到。
特别属性
如果属性名称以“ro.”开头,那么这个属性被视为只读属性。一旦设置,属性值不能改变。
如果属性名称以“persist.”开头,当设置这个属性时,其值也将写入/data/property。
在c++中就是对应JAVA的两个函数就是property_set, property_get,其实JAVA是通过JNI调用这两个函数的。
JAVA
import android.os.SystemProperties;
SystemProperties.set("persist.sys.language", zone.getID());
String lang= SystemProperties.get("persist.sys.language");
C
#include <cutils/properties.h>
property_set("persist.sys.language", "zh");
property_get("persist.sys.language", propLang, "en");
在adb shell可以通过以下的命名读取和修改
#getprop persist.sys.language
#setprop persist.sys.language zh
2 使用 Settings.System.putInt
这种方式会保存变量到Settings 数据库中,飞行模式等的开关就是用这种方式实现的。
在AndroidManifest.xml中包含权限:
<uses-permission android:name=”android.permission.WRITE_SETTINGS” />
在需要发送数据的java文件中,包含:
import android.provider.Settings;
import android.content.ContentResolver;
ContentResolver resolver = mContext.getContentResolver();
Settings.System.putInt(resolver,”inputFlag”,1);
同理,在接收数据端:
Settings.System.getInt(resolver,”inputFlag”,3);
mContext为所在应用的上下文。
1 使用 SystemProperties.get
这中方法在framework里面 经常见到。
特别属性
如果属性名称以“ro.”开头,那么这个属性被视为只读属性。一旦设置,属性值不能改变。
如果属性名称以“persist.”开头,当设置这个属性时,其值也将写入/data/property。
在c++中就是对应JAVA的两个函数就是property_set, property_get,其实JAVA是通过JNI调用这两个函数的。
JAVA
import android.os.SystemProperties;
SystemProperties.set("persist.sys.language", zone.getID());
String lang= SystemProperties.get("persist.sys.language");
C
#include <cutils/properties.h>
property_set("persist.sys.language", "zh");
property_get("persist.sys.language", propLang, "en");
在adb shell可以通过以下的命名读取和修改
#getprop persist.sys.language
#setprop persist.sys.language zh
2 使用 Settings.System.putInt
这种方式会保存变量到Settings 数据库中,飞行模式等的开关就是用这种方式实现的。
在AndroidManifest.xml中包含权限:
<uses-permission android:name=”android.permission.WRITE_SETTINGS” />
在需要发送数据的java文件中,包含:
import android.provider.Settings;
import android.content.ContentResolver;
ContentResolver resolver = mContext.getContentResolver();
Settings.System.putInt(resolver,”inputFlag”,1);
同理,在接收数据端:
Settings.System.getInt(resolver,”inputFlag”,3);
mContext为所在应用的上下文。
相关文章推荐
- Android多线程任务的优化1:AsyncTask的缺陷 (转至 http://www.linuxidc.com/Linux/2011-09/43150.htm)
- http://www.linuxidc.com/Linux/2011-08/40169.htm
- Linux下快速搭建ntp时间同步服务器(转载:http://www.linuxidc.com/Linux/2014-07/104371.htm)
- http://www.linuxidc.com/Linux/2014-09/106310.htm
- Linux中的spinlock和mutex 本篇文章来源于 Linux公社网站(www.linuxidc.com) 原文链接:http://www.linuxidc.com/Linux/2011-
- http://www.linuxidc.com/Linux/2014-06/102856.htm
- Linux 内核编程之文件系统 VFS中的目录项对象和文件对象 http://www.linuxidc.com/Linux/2011-02/32127p2.htm
- vim简单配置(cp:http://www.linuxidc.com/Linux/2014-02/96396.htm)
- MySQL字符集设置—MySQL数据库乱码问题 本篇文章来源于 Linux公社网站(www.linuxidc.com) 原文链接:http://www.linuxidc.com/Linux/2011-01/31531.htm
- linux mkdir http://www.linuxidc.com/Linux/2011-04/35180.htm
- Android开发:用getDrawingCache方法获取ImageView中的图像需要注意的问题 本篇文章来源于 Linux公社网站(www.linuxidc.com) 原文链接:http:/
- 新手对Bash环境变量解析漏洞的理解 http://www.linuxidc.com/Linux/2014-10/107984.htm
- ubuntu中xen-tools安装半虚拟化的虚拟机(转自http://www.linuxidc.com/Linux/2012-04/58209.htm)
- Socket网络通讯开发总结之:Java 与 C进行Socket通讯【转】from http://www.linuxidc.com/Linux/2012-06/63173.htm
- Linux内核部件分析 更强的链表klist 本篇文章来源于 Linux公社网站(www.linuxidc.com) 原文链接:http://www.linuxidc.com/Linux/2011
- http://www.linuxidc.com/Linux/2012-10/72284.htm
- sourceinsight(cp:http://www.linuxidc.com/Linux/2012-07/65603.htm)
- 【转】HBase技术介绍 转载自 http://www.searchtb.com/2011/01/understanding-hbase.html
- Linux下用内存管理器的钩子函数跟踪内存泄漏 本篇文章来源于 Linux公社网站(www.linuxidc.com) 原文链接:http://www.linuxidc.com/Linux/200
- 跨平台(WIndows, Linux, VxWorks) getTickCount实现 本篇文章来源于 Linux公社网站(www.linuxidc.com) 原文链接:http://www.li