本文整理汇总了Java中android.telephony.TelephonyManager.getCellLocation方法的典型用法代码示例。如果您正苦于以下问题:Java TelephonyManager.getCellLocation方法的具体用法?Java TelephonyManager.getCellLocation怎么用?Java TelephonyManager.getCellLocation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.telephony.TelephonyManager
的用法示例。
在下文中一共展示了TelephonyManager.getCellLocation方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getIpBaseStation
import android.telephony.TelephonyManager; //导入方法依赖的package包/类
public static String getIpBaseStation() {
TelephonyManager telMgr = (TelephonyManager) FDApplication
.getInstance().getSystemService(Context.TELEPHONY_SERVICE);
int cid = 0;
int lac = 0;
try {
if (telMgr != null) {
GsmCellLocation gc = (GsmCellLocation) telMgr.getCellLocation();
if (null == gc) {
return "0_0";
}
cid = gc.getCid();
lac = gc.getLac();
}
} catch (Exception e) {
if (telMgr != null) {
CdmaCellLocation location = (CdmaCellLocation) telMgr
.getCellLocation();
if (null == location) {
return "0_0";
}
lac = location.getNetworkId();
cid = location.getBaseStationId();
cid /= 16;
}
}
return lac + "_" + cid;
}
示例2: getTowerValues
import android.telephony.TelephonyManager; //导入方法依赖的package包/类
private int[] getTowerValues() {
// Find new values
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
// Find the location
if (tm == null) {
popupMsg("Could not get TelephonyManager");
return null;
}
int phoneType = tm.getPhoneType();
if (phoneType != TelephonyManager.PHONE_TYPE_CDMA) {
popupMsg("Only CDMA is supported");
return null;
}
CellLocation cl = tm.getCellLocation();
if (cl == null) {
popupMsg("Could not get Cell Location");
return null;
}
if (!(cl instanceof CdmaCellLocation)) {
popupMsg("Cell Location is is not a CdmaCellLocation class");
return null;
}
CdmaCellLocation cdmacl = (CdmaCellLocation) cl;
int lat = NetworkActivity.locToGoogle(cdmacl.getBaseStationLatitude());
int lon = NetworkActivity.locToGoogle(cdmacl.getBaseStationLongitude());
int nid = cdmacl.getNetworkId();
int sid = cdmacl.getSystemId();
int bid = cdmacl.getBaseStationId();
Log.d(TAG, " New values: " + " lat=" + lat + " lon=" + lon + " nid="
+ nid + " sid=" + sid + " bid=" + bid);
return new int[] { lat, lon, nid, sid, bid };
}
示例3: getGSMInfo
import android.telephony.TelephonyManager; //导入方法依赖的package包/类
public static GSMInfo getGSMInfo(Context context) {
try {
GSMInfo info = new GSMInfo();
TelephonyManager manager = (TelephonyManager) context.getSystemService("phone");
if (manager != null) {
CellLocation cellLocation = manager.getCellLocation();
int lac = 0;
int cellid = 0;
if (cellLocation != null) {
if (cellLocation instanceof GsmCellLocation) {
lac = ((GsmCellLocation) cellLocation).getLac();
cellid = ((GsmCellLocation) cellLocation).getCid();
} else if (cellLocation instanceof CdmaCellLocation) {
cellid = ((CdmaCellLocation) cellLocation).getNetworkId();
lac = ((CdmaCellLocation) cellLocation).getBaseStationId();
}
}
info.lac = lac;
info.cid = cellid;
}
AMapLocation location = AMapLocationTool.getInstance().location();
if (location != null) {
info.latitude = location.getLatitude();
info.longitude = location.getLongitude();
return info;
}
info.latitude = Double.parseDouble(PreferencesManager.getInstance().getLocationLongitude());
info.longitude = Double.parseDouble(PreferencesManager.getInstance().getLocationLatitude());
return info;
} catch (Exception e) {
LogInfo.log("ZSM++ ==== GSM exception e == " + e.getMessage());
e.printStackTrace();
return null;
}
}