RK:android 关于SystemProperties的使用

一.system权限
1.在AndroidManifest.xml中,在manifest加入android:sharedUserId="android.uid.system"
2.在Android.mk中,將LOCAL_CERTIFICATE := XXX修改成LOCAL_CERTIFICATE :=platform
3.import android.os.SystemProperties;

二.SystemProperties

Initial_password = SystemProperties.get("persist.passwd.install", "888888");
2.1.getInt
SystemProperties.set("persist.sys.dialog_install","1");

if(SystemProperties.getInt("persist.sys.dialog_install",0) == 1)
{
				auxiliaryDialog.setChecked(true);
}else{
		auxiliaryDialog.setChecked(false);
}
2.2.getBoolean
SystemProperties.set("persist.rotation.limit","true");

if(SystemProperties.getBoolean("persist.rotation.limit",true))
{
				rotation_limit.setChecked(true);
}else{
		rotation_limit.setChecked(false);
}	

三.非系统开发,反射调用

3.1.getProperty

	@SuppressWarnings("finally")
	public String getProperty(String key) {
		String value = "unknown";
		try {
			Class<?> c = Class.forName("android.os.SystemProperties");
			Method get = c.getMethod("get", String.class, String.class);
			value = (String) (get.invoke(c, key, "unknown"));
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			return value;
		}
	}

3.1.setProperty

	public void setProperty(String key, String value) {
		try {
			Class<?> c = Class.forName("android.os.SystemProperties");
			Method set = c.getMethod("set", String.class, String.class);
			set.invoke(c, key, value);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

 四.非系统开发,framework jar包调用 

 framework编译出   out	argetcommonobjJAVA_LIBRARIESframework_intermediates

  

    

 

原文地址:https://www.cnblogs.com/crushgirl/p/13392501.html