Android命令行/c语言/java设置获取系统属性(getprop/setprop)的方法


from:http://www.mikewootc.com/wiki/android/other/system_property.html

date: 2013.07.09; modification:2013.07.09

目录:

Android提供了一套系统参数设置和获取的方法,这些参数可以在android系统中静态或动态的设定和获取。

1 命令行(shell) properties设置和获取接口

getprop “key”

setprop "key" "value"

2 c/c++语言 properties设置和获取接口

代码定义在:

1
2
3
4
5
6
7
8
system /core/libcutils/properties.c
 
#define PROPERTY_KEY_MAX   32
#define PROPERTY_VALUE_MAX  92
 
int property_get( const char *key, char *value, const char *default_value);
int property_set( const char *key, const char *value);
int property_list( void (*propfn)( const char *key, const char *value, void *cookie), void *cookie);   

使用:

1
2
3
4
5
6
#include "cutils/properties.h"
 
char prop[PROPERTY_VALUE_MAX] = "000" ;
if (property_get( "prop_name" , prop, NULL) != 0) {
     ...
}

说明:

  • property_get返回值为get到的属性值的字符串长度.
  • prop_name为属性名.
  • prop为存放属性值字符串的地方.
  • 对应的库为libcutils.so,NDK中没有

3 Java语言 properties设置和获取的接口

frameworks/base/core/java/android/os/SystemProperties.java

1
2
3
4
5
6
7
8
9
public static final int PROP_NAME_MAX = 31 ;
public static final int PROP_VALUE_MAX = 91 ;
public static String get(String key) ;
public static String get(String key, String def) ;
public static int getInt(String key, int def) ;
public static long getLong(String key, long def) ;
public static boolean getBoolean(String key, boolean def) ;
public static void set(String key, String val) ;
public static void addChangeCallback(Runnable callback) ;

4 参考资料

http://blog.csdn.net/flyingqr/article/details/8617519

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值