天天看點

android build.prop解析

轉來兩篇不錯的文章

build.prop檔案詳細賞析(CM/MIUI)

http://www.miui.com/article-239-1.html

分析,讀取 android build.prop

轉自http://blog.sina.com.cn/s/blog_7452896e0101393y.html

android系統屬性build.prop,所在位置:out\target\product\kylin\system\build.prop

用資料線連接配接android 設定,進入調試模式 (在android的設定--應用程式--開發--USB調試)

開始--運作--CMD

C:\Documents and Settings\Administrator>adb shell

# cd system

cd system

# ls

ls

app build.prop fonts lib usr

bin etc framework media xbin

可以看到build.prop,這個就是系統的屬性表,若要COPY出來,這樣操作:

比如COPY到D盤的 leo目錄下

C:\Documents and Settings\Administrator>adb pull system/build.prop d://leo

120 KB/s (0 bytes in 1925.000s)

C:\Documents and Settings\Administrator>

可用記事本打開檢視

若要在java代碼裡讀取裡面的屬性值,則需用到android.os.SystemProperties這個類,此類未開放(未提供給SDK API),

此類具體位置:frameworks\base\core\java\android\os\SystemProperties.java

能夠在frameworks裡面使用,

比如在所有檔案policies\base\phone\com\android\internal\policy\impl\LockScreen.java

裡使用 final boolean isMonkey = SystemProperties.getBoolean("ro.monkey", false);

也能夠在android自帶的APP 裡使用,比如在Settings app裡使用

packages\apps\Settings\src\com\android\settings\deviceinfo\Status.java

//leo added for KYLIN-529

if(SystemProperties.get("ro.product.name").equals("surfone_citic"))

程式的實作看這裡:

try {

Class<?> classType = Class.forName("android.os.SystemProperties");

// Method[] method = classType.getDeclaredMethods();

//

// for(int i = 0 ;i<method.length;i++){

// Log.i("test", method[i].getName());

// }

//

Method getMethod = classType.getDeclaredMethod("get", new Class<?>[]{String.class});

String value = (String) getMethod.invoke(classType, new Object[]{"YOUKEY"});

Log.i("test", value);