/**
* Retrieves network info data. *
*
* @return Current network info data.
*/
public static NetworkState getNetworkState(Context context) {
NetworkState callInfoData = null;
try {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
GsmCellLocation location = (GsmCellLocation) telephonyManager.getCellLocation();
String mcc = "0";
String mnc = "0";
String networkOperator = telephonyManager.getNetworkOperator();
if (networkOperator != null && networkOperator.length() > 0) {
mcc = telephonyManager.getNetworkOperator().substring(0, 3);
mnc = telephonyManager.getNetworkOperator().substring(3);
}
int[] neighborCellId;
int[] neighborCellRssi;
List<NeighboringCellInfo> neighboringList = telephonyManager.getNeighboringCellInfo();
if (neighboringList != null && !neighboringList.isEmpty()) {
neighborCellId = new int[neighboringList.size()];
neighborCellRssi = new int[neighboringList.size()];
for (int i = 0; i < neighboringList.size(); i++) {
neighborCellRssi[i] = neighboringList.get(i).getRssi();
neighborCellId[i] = neighboringList.get(i).getCid();
}
} else {
neighborCellId = new int[] { -1 };
neighborCellRssi = new int[] { -1 };
}
callInfoData = new NetworkState(System.currentTimeMillis(), (location != null) ? location.getCid() : 0, /* rssi, dbm, asu, */0, 0, 0,
mcc, mnc, (location != null) ? location.getLac() : 0, NetworkUtils.isInRoaming(context),
NetworkUtils.getDataConnectionState(context), NetworkUtils.getSimState(context), NetworkUtils.getNetworkType(context),
NetworkUtils.isWiFiEnabled(context), neighborCellId, neighborCellRssi);
} catch (final Exception e) {
Logger.logApplicationException(e, NetworkUtils.class.getSimpleName() + ".getNetworkInfoData(): Failed.");
e.printStackTrace();
}
return callInfoData;
}
NetworkUtils.java 文件源码
java
阅读 30
收藏 0
点赞 0
评论 0
项目:Office-365-SDK-for-Android
作者:
评论列表
文章目录