本文整理了Java中android.telephony.TelephonyManager.getCellLocation()
方法的一些代码示例,展示了TelephonyManager.getCellLocation()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TelephonyManager.getCellLocation()
方法的具体详情如下:
包路径:android.telephony.TelephonyManager
类名称:TelephonyManager
方法名:getCellLocation
暂无
代码示例来源:origin: square/assertj-android
public TelephonyManagerAssert hasCellLocation(CellLocation cellLocation) {
isNotNull();
CellLocation actualCellLocation = actual.getCellLocation();
assertThat(actualCellLocation) //
.overridingErrorMessage("Expected cell location <%s> but was <%s>.", cellLocation,
actualCellLocation) //
.isEqualTo(cellLocation);
return this;
}
代码示例来源:origin: wangdan/AisenWeiBo
GsmCellLocation location = null;
if (mTelNet != null)
location = (GsmCellLocation) mTelNet.getCellLocation();
if (location != null) {
String operator = mTelNet.getNetworkOperator();
代码示例来源:origin: jiangqqlmj/FastDev4Android
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;
}
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldGiveCellLocation() {
PhoneStateListener listener = mock(PhoneStateListener.class);
telephonyManager.listen(listener, LISTEN_CELL_LOCATION);
CellLocation mockCellLocation = mock(CellLocation.class);
shadowOf(telephonyManager).setCellLocation(mockCellLocation);
assertEquals(mockCellLocation, telephonyManager.getCellLocation());
verify(listener).onCellLocationChanged(mockCellLocation);
}
代码示例来源:origin: stackoverflow.com
final TelephonyManager telephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if (telephony.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) {
final GsmCellLocation location = (GsmCellLocation) telephony.getCellLocation();
if (location != null) {
msg.setText("LAC: " + location.getLac() + " CID: " + location.getCid());
}
}
代码示例来源:origin: qyxxjd/AndroidBasicProject
/**
* 返回设备的当前位置
* <p>Requires Permission:
* {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_COARSE_LOCATION} or
* {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION}.
* @return GsmCellLocation
*/
public GsmCellLocation getGsmCellLocation(){
return (GsmCellLocation) sTelephonyManager.getCellLocation();
}
代码示例来源:origin: qyxxjd/BaseProject
/**
* 返回设备的当前位置
* <p>Requires Permission:
* {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_COARSE_LOCATION} or
* {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION}.
*
* @return GsmCellLocation
*/
@SuppressLint("MissingPermission")
public GsmCellLocation getGsmCellLocation() {
return (GsmCellLocation) mTelephonyManager.getCellLocation();
}
代码示例来源:origin: stackoverflow.com
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
GsmCellLocation location = (GsmCellLocation) tm.getCellLocation();
String IMEI = tm.getDeviceId();
int lac = location.getLac();
... ...
代码示例来源:origin: stackoverflow.com
final TelephonyManager telephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if (telephony.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) {
final GsmCellLocation location = (GsmCellLocation) telephony.getCellLocation();
if (location != null) {
msg.setText("LAC: " + location.getLac() + " CID: " + location.getCid());
}
}
代码示例来源:origin: stackoverflow.com
final TelephonyManager telephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if (telephony.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) {
final GsmCellLocation location = (GsmCellLocation) telephony.getCellLocation();
if (location != null) {
lac.setText("LAC: " + location.getLac() + " CID: " + location.getCid());
}
}
代码示例来源:origin: renyuneyun/Easer
@SuppressLint("MissingPermission")
@Override
public Boolean state() {
return match(telephonyManager.getCellLocation());
}
代码示例来源:origin: stackoverflow.com
final TelephonyManager telephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if (telephony.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) {
final GsmCellLocation location = (GsmCellLocation) telephony.getCellLocation();
if (location != null) {
String LAC= location.getLac() ;
String CID= location.getCid();
}
}
代码示例来源:origin: stackoverflow.com
TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
CellLocation cl = tm.getCellLocation();
GsmCellLocation gsmLoc;
CdmaCellLocation cdmaLoc;
try {
gsmLoc = (GsmCellLocation) cl;
System.out.println("Cell id " + gsmLoc.getCid());
System.out.println("Lac - " + gsmLoc.getLac());
System.out.println("Psc - " + gsmLoc.getPsc());
} catch (ClassCastException e) {
cdmaLoc = (CdmaCellLocation) cl;
System.out.println("Base station ID - "+ cdmaLoc.getBaseStationId());
System.out.println("Base station Latitude - "+ cdmaLoc.getBaseStationLatitude());
System.out.println("Network Id - "+ cdmaLoc.getNetworkId());
System.out.println("System ID -"+ cdmaLoc.getSystemId());
}
System.out.println("Operator Name - "+ tm.getNetworkOperatorName());
代码示例来源:origin: com.squareup.assertj/assertj-android
public TelephonyManagerAssert hasCellLocation(CellLocation cellLocation) {
isNotNull();
CellLocation actualCellLocation = actual.getCellLocation();
assertThat(actualCellLocation) //
.overridingErrorMessage("Expected cell location <%s> but was <%s>.", cellLocation,
actualCellLocation) //
.isEqualTo(cellLocation);
return this;
}
代码示例来源:origin: stackoverflow.com
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
GsmCellLocation cellLocation = (GsmCellLocation) telephonyManager
.getCellLocation();
// Cell Id, LAC
int cellid = cellLocation.getCid();
int lac = cellLocation.getLac();
// MCC
String MCC = telephonyManager.getNetworkOperator();
int mcc = Integer.parseInt(MCC.substring(0, 3));
// Operator name
String operatoprName = telephonyManager.getNetworkOperatorName();
代码示例来源:origin: liudao01/EventCollect
/**
* 获取基站定位数据
* @param context
* @return
*/
public static String getCellLocation(Context context) {
if (!checkPermission(context, Manifest.permission.READ_PHONE_STATE)) {
return "";
}
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (tm == null) {
return "";
}
CellLocation cellLocation = tm.getCellLocation();
if (cellLocation == null) {
return "";
}
return cellLocation.toString();
}
代码示例来源:origin: stackoverflow.com
GsmCellLocation cellLocation = (GsmCellLocation) telephonyManager.getCellLocation();
int cid = cellLocation.getCid();
int lac = cellLocation.getLac();
代码示例来源:origin: microg/android_external_UnifiedNlpApi
@SuppressWarnings("deprecation")
private synchronized void fallbackScan() {
if (lastScan + MIN_UPDATE_INTERVAL > System.currentTimeMillis()) return;
List<CellInfo> allCellInfo = telephonyManager.getAllCellInfo();
if ((allCellInfo == null || allCellInfo.isEmpty()) && telephonyManager.getNetworkType() > 0) {
allCellInfo = new ArrayList<CellInfo>();
CellLocation cellLocation = telephonyManager.getCellLocation();
CellInfo cellInfo = fromCellLocation(cellLocation);
if (cellInfo != null) allCellInfo.add(cellInfo);
}
onCellsChanged(allCellInfo);
}
代码示例来源:origin: renyuneyun/Easer
@SuppressLint("MissingPermission")
@Override
public void check() {
if (!PluginHelper.checkPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION))
return;
CellLocationListener chck = new CellLocationListener();
chck.onCellLocationChanged(telephonyManager.getCellLocation());
}
代码示例来源:origin: renyuneyun/Easer
@Override
public void onClick(View view) {
if (!Utils.hasPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION))
return;
TelephonyManager telephonyManager = (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE);
if (telephonyManager == null) {
Toast.makeText(getContext(), R.string.event_cell_location_no_signal, Toast.LENGTH_SHORT).show();
return;
}
@SuppressLint("MissingPermission") CellLocationSingleData singleData = CellLocationSingleData.fromCellLocation(telephonyManager.getCellLocation());
if (singleData == null) {
Toast.makeText(getContext(), R.string.event_cell_location_no_signal, Toast.LENGTH_SHORT).show();
return;
}
CellLocationEventData locationData = CellLocationEventData.fromString(editText.getText().toString());
if (locationData == null)
locationData = new CellLocationEventData();
locationData.add(singleData);
editText.setText(locationData.toString());
}
});
内容来源于网络,如有侵权,请联系作者删除!