国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

github項目之讀取系統屬性

2019-11-06 09:38:08
字體:
來源:轉載
供稿:網友

這里寫圖片描述

前言

android開發中,我們經常需要讀取系統屬性值,這個讀取系統屬性值的方法有許多: (1)手機連接電腦,在電腦終端中輸入:adb shell getPRop **,就可以讀取到對應的系統屬性。 此方法需要將手機連接電話,并且需要將手機的USB 調試功能打開,這其實就影響到了對應的USB相關的系統屬性。

(2)Systemproperties類來實現 Systemproperties.set(name, value) Systemproperties.get(name) 這二個方法可以實現對系統屬性讀取和操作,但是可惜啊,此方法需要在AndroidManifest.xml中,加入android:sharedUserId=”android.uid.system”。 并且在Android.mk中,將LOCAL_CERTIFICATE := XXX修改成LOCAL_CERTIFICATE :=platform。 經過以上兩步就可以把ap的權限提升到system權限了。

但是用這種方法: 1、程序的擁有者必須有程序的源碼; 2、程序的擁有者還必須有android開發環境,就是說自己能make整個android系統。

這一般的應用開發者,都是不具備此條件的。

/system/bin/getprop實現系統屬性的讀取操作

此方法是使用/system/bin/getprop,來實現系統屬性的讀取操作,可以不需要連接電腦,不需要打開USB調試,不需要提高開發者權限到system,像正常的應用一樣,直接顯示系統屬性。

效果圖:

核心代碼:

(1)讀取系統屬性

private String commandPro ="/system/bin/getprop";private static final String OUTPUT_FILE = Environment.getExternalStorageDirectory().toString() + "/prop_all.txt";//執行讀取系統屬性的命令restul = PropHelper.execCommand(command);public static String execCommand(String command) throws IOException { String result = "fail02"; Runtime runtime = Runtime.getRuntime(); Process proc = runtime.exec(command); try { if (proc.waitFor() != 0) { System.err.println("exit value = " + proc.exitValue()); return result; } BufferedReader in = new BufferedReader( new InputStreamReader(proc.getInputStream())); StringBuffer stringBuffer = new StringBuffer(); String line = null; while ((line = in.readLine()) != null) { stringBuffer.append(line+" /n"); } result = stringBuffer.toString(); return result; } catch (InterruptedException e) { System.err.println(e); return "fail03"; } }

(2)將讀取的系統屬性保存到SD卡

//將讀取的系統屬性保存到SD卡boolean success = PropHelper.saveToSDCard(restul,OUTPUT_FILE);public static boolean saveToSDCard(String content,String des) { boolean result = true; FileOutputStream fos = null; try { File f1 = new File(des); if(f1.exists()){ f1.delete(); } f1.createNewFile(); fos = new FileOutputStream(f1); fos.write(content.getBytes()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); result = false; return result; }finally{ try { if(fos != null){ fos.close(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); result = false; return result; } } return result; }

源碼地址:

https://github.com/hfreeman2008/AndroidDevelopHelper


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 南开区| 客服| 高密市| 芮城县| 舟山市| 陕西省| 林甸县| 道孚县| 广宗县| 新晃| 彭水| 广灵县| 射阳县| 咸丰县| 邵武市| 莒南县| 平潭县| 榆林市| 沂水县| 六盘水市| 桃江县| 黑龙江省| 周至县| 施甸县| 边坝县| 唐山市| 七台河市| 湛江市| 井研县| 甘谷县| 普格县| 黑水县| 原阳县| 胶州市| 临漳县| 云浮市| 策勒县| 陈巴尔虎旗| 迭部县| 夹江县| 政和县|