/**
* 系统信息工具类
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public class SystemInfoUtil {
/**
* 获取系统里面正在运行的进程的个数
*/
public static int getRunningProcessCount(Context context) {
ActivityManager am = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> runningAppProcesses = am
.getRunningAppProcesses();
return runningAppProcesses.size();
}
/**
* 获取系统可用的内存信息
*/
public static long getAvailMem(Context context) {
ActivityManager am = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
MemoryInfo memoryInfo = new MemoryInfo();
am.getMemoryInfo(memoryInfo);
return memoryInfo.availMem;
}
/**
* 获取系统总的内存信息
*/
public static long getTotalMem(Context context) {
long totalMem = 0;
/* 获取当前系统的android版本号 */
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
// 系统版本大于16
ActivityManager am = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
MemoryInfo memoryInfo = new MemoryInfo();
am.getMemoryInfo(memoryInfo);
totalMem = memoryInfo.totalMem;// 系统版本大于16的API
} else {
try {
// 系统版低于16
File file = new File("/proc/meminfo");
FileInputStream fis = new FileInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(
fis));
// MemTotal: 516452 kB
String line = br.readLine();
// 字符串 一组字符--串
StringBuffer sb = new StringBuffer();
for (char c : line.toCharArray()) {
if (c >= '0' && c <= '9') {
sb.append(c);
}
}
totalMem = Integer.parseInt(sb.toString()) * 1024; // byte
} catch (Exception e) {
e.printStackTrace();
}
}
return totalMem;
}
}
* 系统信息工具类
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public class SystemInfoUtil {
/**
* 获取系统里面正在运行的进程的个数
*/
public static int getRunningProcessCount(Context context) {
ActivityManager am = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> runningAppProcesses = am
.getRunningAppProcesses();
return runningAppProcesses.size();
}
/**
* 获取系统可用的内存信息
*/
public static long getAvailMem(Context context) {
ActivityManager am = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
MemoryInfo memoryInfo = new MemoryInfo();
am.getMemoryInfo(memoryInfo);
return memoryInfo.availMem;
}
/**
* 获取系统总的内存信息
*/
public static long getTotalMem(Context context) {
long totalMem = 0;
/* 获取当前系统的android版本号 */
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
// 系统版本大于16
ActivityManager am = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
MemoryInfo memoryInfo = new MemoryInfo();
am.getMemoryInfo(memoryInfo);
totalMem = memoryInfo.totalMem;// 系统版本大于16的API
} else {
try {
// 系统版低于16
File file = new File("/proc/meminfo");
FileInputStream fis = new FileInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(
fis));
// MemTotal: 516452 kB
String line = br.readLine();
// 字符串 一组字符--串
StringBuffer sb = new StringBuffer();
for (char c : line.toCharArray()) {
if (c >= '0' && c <= '9') {
sb.append(c);
}
}
totalMem = Integer.parseInt(sb.toString()) * 1024; // byte
} catch (Exception e) {
e.printStackTrace();
}
}
return totalMem;
}
}