Java Code Examples for android.telephony.TelephonyManager#getCellLocation()

The following examples show how to use android.telephony.TelephonyManager#getCellLocation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GnssLocationProvider.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Called from native code to request reference location info
 */
private void requestRefLocation() {
    TelephonyManager phone = (TelephonyManager)
            mContext.getSystemService(Context.TELEPHONY_SERVICE);
    final int phoneType = phone.getPhoneType();
    if (phoneType == TelephonyManager.PHONE_TYPE_GSM) {
        GsmCellLocation gsm_cell = (GsmCellLocation) phone.getCellLocation();
        if ((gsm_cell != null) && (phone.getNetworkOperator() != null)
                && (phone.getNetworkOperator().length() > 3)) {
            int type;
            int mcc = Integer.parseInt(phone.getNetworkOperator().substring(0, 3));
            int mnc = Integer.parseInt(phone.getNetworkOperator().substring(3));
            int networkType = phone.getNetworkType();
            if (networkType == TelephonyManager.NETWORK_TYPE_UMTS
                    || networkType == TelephonyManager.NETWORK_TYPE_HSDPA
                    || networkType == TelephonyManager.NETWORK_TYPE_HSUPA
                    || networkType == TelephonyManager.NETWORK_TYPE_HSPA
                    || networkType == TelephonyManager.NETWORK_TYPE_HSPAP) {
                type = AGPS_REF_LOCATION_TYPE_UMTS_CELLID;
            } else {
                type = AGPS_REF_LOCATION_TYPE_GSM_CELLID;
            }
            native_agps_set_ref_location_cellid(type, mcc, mnc,
                    gsm_cell.getLac(), gsm_cell.getCid());
        } else {
            Log.e(TAG, "Error getting cell location info.");
        }
    } else if (phoneType == TelephonyManager.PHONE_TYPE_CDMA) {
        Log.e(TAG, "CDMA not supported.");
    }
}
 
Example 2
Source File: LetvUtils.java    From letv with Apache License 2.0 5 votes vote down vote up
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;
    }
}
 
Example 3
Source File: Gsm.java    From batteryhub with Apache License 2.0 5 votes vote down vote up
public static CellInfo getCellInfo(Context context) {
    CellInfo cellInfo = new CellInfo();

    TelephonyManager manager = (TelephonyManager)
            context.getSystemService(Context.TELEPHONY_SERVICE);

    String netOperator = manager.getNetworkOperator();

    // Fix crash when not connected to network (airplane mode, underground,
    // etc)
    if (netOperator == null || netOperator.length() < 3) {
        return cellInfo;
    }

    /*
     * FIXME: Actually check for mobile network status == connected before
     * doing this stuff.
     */

    if (Phone.getType(context).equals(PHONE_TYPE_CDMA)) {
        CdmaCellLocation cdmaLocation = (CdmaCellLocation) manager.getCellLocation();

        cellInfo.cid = cdmaLocation.getBaseStationId();
        cellInfo.lac = cdmaLocation.getNetworkId();
        cellInfo.mnc = cdmaLocation.getSystemId();
        cellInfo.mcc = Integer.parseInt(netOperator.substring(0, 3));
        cellInfo.radioType = Network.getMobileNetworkType(context);
    } else if (Phone.getType(context).equals(PHONE_TYPE_GSM)) {
        GsmCellLocation gsmLocation = (GsmCellLocation) manager.getCellLocation();

        cellInfo.mcc = Integer.parseInt(netOperator.substring(0, 3));
        cellInfo.mnc = Integer.parseInt(netOperator.substring(3));
        cellInfo.lac = gsmLocation.getLac();
        cellInfo.cid = gsmLocation.getCid();
        cellInfo.radioType = Network.getMobileNetworkType(context);
    }

    return cellInfo;
}
 
Example 4
Source File: TelephonyActivity.java    From nearbydemo with Eclipse Public License 1.0 5 votes vote down vote up
private String getJsonCellPos() throws JSONException {
	TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
	GsmCellLocation location = (GsmCellLocation) tm.getCellLocation();
	if (location == null) {
		return null;
	}
	int cid = location.getCid();
	int lac = location.getLac();
	String netOperator = tm.getNetworkOperator();
	int mcc = Integer.valueOf(netOperator.substring(0, 3));
	int mnc = Integer.valueOf(netOperator.substring(3, 5));
	System.out.println("cid" + cid + ",lac" + lac + ",mcc" + mcc + "" + ",mnc" + mnc);
	JSONObject jsonCellPos = new JSONObject();
	jsonCellPos.put("version", "1.1.0");
	jsonCellPos.put("host", "maps.google.com");

	JSONArray array = new JSONArray();
	JSONObject json1 = new JSONObject();
	json1.put("location_area_code", "" + lac + "");
	json1.put("mobile_country_code", "" + mcc + "");
	json1.put("mobile_network_code", "" + mnc + "");
	json1.put("age", 0);
	json1.put("cell_id", "" + cid + "");
	array.put(json1);
	jsonCellPos.put("cell_towers", array);
	return jsonCellPos.toString();
}
 
Example 5
Source File: TelephonyActivity.java    From nearbydemo with Eclipse Public License 1.0 5 votes vote down vote up
public String getJsonCellPos1() {
	TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
	GsmCellLocation location = (GsmCellLocation) tm.getCellLocation();
	if (location == null) {
		return null;
	}
	int cid = location.getCid();
	int lac = location.getLac();
	String netOperator = tm.getNetworkOperator();
	int mcc = Integer.valueOf(netOperator.substring(0, 3));
	int mnc = Integer.valueOf(netOperator.substring(3, 5));
	System.out.println("cid" + cid + ",lac" + lac + ",mcc" + mcc + "" + ",mnc" + mnc);
	holder = new JSONObject();
	JSONArray array = new JSONArray();
	JSONObject data = new JSONObject();
	try {
		holder.put("version", "1.1.0");
		holder.put("host", "maps.google.com");
		holder.put("address_language", "zh_CN");
		holder.put("request_address", true);
		holder.put("radio_type", "gsm");
		holder.put("carrier", "HTC");
		data.put("cell_id", cid);
		data.put("location_area_code", lac);
		data.put("mobile_countyr_code", mcc);
		data.put("mobile_network_code", mnc);
		array.put(data);
		holder.put("cell_towers", array);
		Log.i(TAG, "JSON��Ϣ��" + holder.toString());
		return holder.toString();
	} catch (JSONException e) {
		e.printStackTrace();
	}
	return null;

}
 
Example 6
Source File: NetUtil.java    From ESeal with Apache License 2.0 4 votes vote down vote up
/**
 * 获取手机基站的LAC (Location Aera Code)
 */
public static int getCellLocationLac(Activity activity) {
    TelephonyManager telephonyManager = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
    GsmCellLocation location = (GsmCellLocation) telephonyManager.getCellLocation();
    return location.getLac();
}
 
Example 7
Source File: NetUtil.java    From ESeal with Apache License 2.0 4 votes vote down vote up
/**
 * 获取手机基站的CID (Cell Tower ID)
 */
public static int getCellLocationCid(Activity activity) {
    TelephonyManager telephonyManager = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
    GsmCellLocation location = (GsmCellLocation) telephonyManager.getCellLocation();
    return location.getCid();
}
 
Example 8
Source File: NetUtil.java    From ESeal with Apache License 2.0 4 votes vote down vote up
/**
 * 获取手机基站的LAC (Location Aera Code)
 */
public static int getCellLocationLac(Activity activity) {
    TelephonyManager telephonyManager = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
    GsmCellLocation location = (GsmCellLocation) telephonyManager.getCellLocation();
    return location.getLac();
}
 
Example 9
Source File: NetUtil.java    From ESeal with Apache License 2.0 4 votes vote down vote up
/**
 * 获取手机基站的CID (Cell Tower ID)
 */
public static int getCellLocationCid(Activity activity) {
    TelephonyManager telephonyManager = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
    GsmCellLocation location = (GsmCellLocation) telephonyManager.getCellLocation();
    return location.getCid();
}
 
Example 10
Source File: LocationInfo.java    From batteryhub with Apache License 2.0 4 votes vote down vote up
public static CellLocation getDeviceLocation(Context context) {
    TelephonyManager manager = (TelephonyManager)
            context.getSystemService(Context.TELEPHONY_SERVICE);

    return manager.getCellLocation();
}