android 反射機制及Settings字段讀寫

阅读更多

1.反射

1.1反射-Read:

try{
            Class mSystemPropertiesClass = Class.forName("android.os.SystemProperties");
            Method getProperties = mSystemPropertiesClass.getDeclaredMethod("get", String.class);
            getProperties.setAccessible(true);
            (String) (getProperties.invoke(null, "persist.sys.touch.mode"));
} catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
 }

 1.2反射-Write:

try {
            Class c = Class.forName("android.os.SystemProperties");
            Method set = c.getMethod("set", String.class, String.class);
            set.invoke(c, "persist.sys.touch.mode", value );
} catch (Exception e) {
            e.printStackTrace();
}

value:  String type
stylus
glove

 2.Settings 字段,作用與全局

2.1.Read:

Settings.System.getInt(mContext.getContentResolver(),“wifi_current_frequency_band”, 0);

 2.2.Write:

Settings.System.putInt(mContext.getContentResolver(), “wifi_current_frequency_band”, value);

Value:int type
0: Auto
1: 5GHz
2: 2.4Ghz

 

你可能感兴趣的:(android 反射機制及Settings字段讀寫)