Android开发中,获取存储信息、电量信息。

一、获取手机的存储信息(注意是存储容量,非运行内存信息。)

//获取存储信息

private String getRAMInfo() {

File directory = Environment.getExternalStorageDirectory();

long totalSpace = directory.getTotalSpace();

long usableSpace = directory.getUsableSpace();

String total = Formatter.formatFileSize(this, totalSpace);

String useAble = Formatter.formatFileSize(this, usableSpace);

return "可用 " + useAble +"/总共 " + total;

}

二、获取手机电量信息

//获取电量信息

private int getElectricity() {

try {

BatteryManager batterymanager = (BatteryManager) getSystemService(BATTERY_SERVICE);

int intProperty = batterymanager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);

return intProperty;

}catch (Exception e) {

e.printStackTrace();

return 0;

}

}

你可能感兴趣的:(Android开发中,获取存储信息、电量信息。)