package core.common;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.util.ArrayList;
import java.util.List;
/**
* Created by i on 13-11-30.
*/
public class AndroidOS {
public static boolean isIntentAvailable(Context context, String action)
{
final PackageManager packageManager = context.getPackageManager();
final Intent intent = new Intent(action);
List list = packageManager.queryIntentActivities(intent,PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
}
public static boolean serviceIsRunning(Context c, String serviceName) {
ActivityManager am = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE);
ArrayList<ActivityManager.RunningServiceInfo> runningServices = (ArrayList<ActivityManager.RunningServiceInfo>) am.getRunningServices(100);
for (int i = 0; i < runningServices.size(); i++)//循环枚举对比
{
//System.out.println(runningServices.get(i).service.getClassName().toString());
if (runningServices.get(i).service.getClassName().toString().equals(serviceName)) {
return true;
}
}
return false;
}
/**
* 获取CPU序列号
*
* @return CPU序列号(16位)
* 读取失败为"0000000000000000"
*/
public static String getCPUSerial() {
String str = "", strCPU = "", cpuAddress = "0000000000000000";
try {
//读取CPU信息
Process pp = Runtime.getRuntime().exec("cat /proc/cpuinfo");
InputStreamReader ir = new InputStreamReader(pp.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
//查找CPU序列号
for (int i = 1; i < 100; i++) {
str = input.readLine();
if (str != null) {
//查找到序列号所在行
if (str.indexOf("Serial") > -1) {
//提取序列号
strCPU = str.substring(str.indexOf(":") + 1,
str.length());
//去空格
cpuAddress = strCPU.trim();
break;
}
}else{
//文件结尾
break;
}
}
} catch (IOException ex) {
//赋予默认值
System.out.println(ex.getMessage());
}
return cpuAddress;
}
}