package com.jqyd.shareInterface;
import java.util.ArrayList;
import com.jqyd.app.ShareMethod;
import com.jqyd.model.LocationModule;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.telephony.TelephonyManager;
import android.telephony.cdma.CdmaCellLocation;
import android.telephony.gsm.GsmCellLocation;
import android.util.Log;
public class SystemInfo {
private Context context;
private TelephonyManager tm ;
public SystemInfo(Context context){
this.context = context;
tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
}
/**
* 获得版本信息
* @return
*/
public String getVersionInfo(){
String pName = "com.jqyd.manager";
String versionName = null;
try {
PackageInfo pinfo = context.getPackageManager().getPackageInfo(pName,
PackageManager.GET_CONFIGURATIONS);
versionName = pinfo.versionName;
System.out.println("version:" + versionName);
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return versionName;
}
/**
* 获取当前基站的cid及相关信息
*/
//解释:
//IMSI是国际移动用户识别码的简称(International Mobile Subscriber Identity)
//IMSI共有15位,其结构如下:
//MCC+MNC+MIN
//MCC:Mobile Country Code,移动国家码,共3位,中国为460;
//MNC:Mobile NetworkCode,移动网络码,共2位
//在中国,移动的代码为电00和02,联通的代码为01,电信的代码为03
// public LocationModule takeCellInfos() {
// LocationModule loc = new LocationModule();
// int cid = 0;
// int lac = 0;
// int type = tm.getNetworkType();
// // 在中国,联通的3G为UMTS或HSDPA,移动和联通的2G为GPRS或EGDE,电信的2G为CDMA,电信的3G为EVDO
// // G网
// new ShareMethod(context).recordLog("当前网络类型:"+type);
// try {
// if (type == TelephonyManager.NETWORK_TYPE_UMTS
// || type == TelephonyManager.NETWORK_TYPE_HSDPA
// || type == TelephonyManager.NETWORK_TYPE_EDGE
// || type == TelephonyManager.NETWORK_TYPE_GPRS
// || type == TelephonyManager.NETWORK_TYPE_HSPA
// || type == TelephonyManager.NETWORK_TYPE_HSUPA) {
// GsmCellLocation gcl = (GsmCellLocation) tm.getCellLocation();
// try {
// cid = gcl.getCid();//小区编号
// lac = gcl.getLac();//位置区域码
// } catch (Exception e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// new ShareMethod(context).recordLog("G网获取小区编号或位置区域码出现错误!");
// }
// System.out.println("------------G网cid--------------:" + cid);
// //信号强度
// // C网
// } else if (type == TelephonyManager.NETWORK_TYPE_CDMA
// || type == TelephonyManager.NETWORK_TYPE_EVDO_0
// || type == TelephonyManager.NETWORK_TYPE_EVDO_A) {
// //参考地址:http://topic.csdn.net/u/20110110/23/c2f6524a-8746-4c1b-914e-57c7c9cced02.html
// CdmaCellLocation cdl = (CdmaCellLocation) tm.getCellLocation();
// try {
// cid = cdl.getBaseStationId();
// lac = cdl.getNetworkId();
// } catch (Exception e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// new ShareMethod(context).recordLog("C网获取小区编号或位置区域码出现错误!");
// }
// //信号强度
// System.out.println("------------------C网cid-------------:" + cid);
// }
// } catch (Exception e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// new ShareMethod(context).recordLog("------------读取小区编号时出现异常-------------");
// }
// System.out.println("本机网络类型:"+type);
// loc.setCell_id(cid+"");//小区编号
// loc.setLac(lac+"");//位置区域码
// if(tm.getSubscriberId()!=null&&!tm.getSubscriberId().equals("")){
// loc.setCcode(tm.getSubscriberId().substring(0, 3));//移动国家码
// loc.setNcode(tm.getSubscriberId().substring(3, 5));//移动网络码
// }
// else{
// loc.setCcode("460");
// String operator = tm.getSimOperator();
// if(operator!=null){
// loc.setNcode(operator.substring(3, 5));
// }else{
// loc.setNcode("");
// }
//
// }
// String operator = tm.getSimOperator();
// if(operator!=null){
// if(operator.equals("46000")||operator.equals("46002")){
// //中国移动
// operator = "3";
// }else if(operator.equals("46001")){
// //中国联通
// operator = "1";
// }else if(operator.equals("46003")){
// //中国电信
// operator = "2";
// }
// }else{
// operator = "-1";
// }
// loc.setYys(operator);
// return loc;
// }
/**
* 判断服务是否运行
*
* @return
*/
public boolean isServiceRunning(String pac_act) {
boolean flag = false;
ActivityManager myManager = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
ArrayList<RunningServiceInfo> runningService = (ArrayList<RunningServiceInfo>) myManager
.getRunningServices(Integer.MAX_VALUE);
for (int i = 0; i < runningService.size(); i++) {
if (runningService.get(i).service.getClassName().toString()
.equals(pac_act)) {
flag = true;
}
}
return flag;
}
}