github项目之读取系统属性
来源:互联网 发布:淘宝网30天后执行冻结 编辑:程序博客网 时间:2024/06/03 19:18
前言
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
- github项目之读取系统属性
- 读取JAVA系统属性
- 读取手机系统属性源代码
- GitHub使用之上传项目
- github 项目推荐之个人版
- Github使用之clone项目
- Idea之GitHub项目管理
- java_之读取属性文件
- GitHub上传本地项目 之 Github本地项目上传 (2)
- Mac系统,上传项目到github
- Mac系统 使用github上传项目
- Mac 系统 git上传项目至gitHub
- ubuntu系统github上传本地项目
- 读取项目AssemblyInfo.cs属性值
- .net 读取项目AssemblyInfo.cs属性值
- Java Web项目读取属性文件
- Java之系统属性
- Qt之属性系统
- 文件共享
- Android软件中实现跳转到应用商店进行评分
- Web负载均衡的几种实现方式
- MacBook 怎样进入/users/目录文件夹
- GUI专门做界面效果的类
- github项目之读取系统属性
- Ubuntu中rc.local 中命令不执行
- hadoop 不能本地打开网页
- https原理及tomcat配置https方法
- SpringJPA 源码中CrudRepository和JpaRepository的Save方法的区别分析
- 第二周:[leetCode] 142. Linked List Cycle II
- Elasticsearch--Aggregation详细总结(聚合统计)
- IDEA 快捷键
- 使用springMVC时发送请求报400错误