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; import java.lang.reflect.Method;
二.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); }
2.2.
property_set("persist.sys.audio_device","1"); char pro_value[PROPERTY_VALUE_MAX] = ""; property_get("persist.audio.mic",pro_value,0); ALOGD("persist.audio.mic mic_value %d", mic_value);
三.非系统开发,反射调用
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.2.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\target\common\obj\JAVA_LIBRARIES\framework_intermediates