android获取系统信息

本文介绍了一种在Android设备上通过ADB Shell模式获取系统属性的方法。利用getprop命令结合Java代码实现,可以有效地读取如build.prop文件中的特定属性值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

连接手机,adb shell 进入 Android Shell 模式,输入 getprop 获取系统属性值

通过上面方法拿到属性名,然后通过下面方法获取到系统的属性值

/**
* 获取build.prop文件中的某个属性
*
* @param propName 属性名称
* @return 属性值
*/
public static String getSystemProperty(String propName) {

Log.i(LOG_TAG, "getSystemProperty in time: " + System.currentTimeMillis());
String line;
BufferedReader input = null;
try {
Process p = Runtime.getRuntime().exec("getprop " + propName);
input = new BufferedReader(
new InputStreamReader(p.getInputStream()), 1024);
line = input.readLine();
input.close();
} catch (Exception ex) {
Log.e(LOG_TAG, "Unable to read sysprop " + propName, ex);
return null;
} finally {
if (input != null) {
try {
input.close();
} catch (Exception e) {
Log.e(LOG_TAG, "Exception while closing InputStream", e);
}
}
}

Log.i(LOG_TAG, "getSystemProperty out time: " + System.currentTimeMillis());

return line;
}

 

转载于:https://www.cnblogs.com/agilezhu/p/7694133.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值