Example usage for android.telephony CellLocation requestLocationUpdate

List of usage examples for android.telephony CellLocation requestLocationUpdate

Introduction

In this page you can find the example usage for android.telephony CellLocation requestLocationUpdate.

Prototype

public static void requestLocationUpdate() 

Source Link

Document

Request an update of the current location.

Usage

From source file:at.alladin.rmbt.android.util.InformationCollector.java

private void getTelephonyInfo() {
    initNetwork();//w  w w .j  a v a2s .  c o m
    if (telManager != null) {
        try {
            // Get Cell Location
            CellLocation.requestLocationUpdate();
        } catch (Exception e) {
            // some devices with Android 5.1 seem to throw a NPE is some cases
            e.printStackTrace();
        }

        final CellLocation cellLocation = telManager.getCellLocation();
        if (cellLocation != null && (cellLocation instanceof GsmCellLocation)) {
            final GsmCellLocation gcl = (GsmCellLocation) cellLocation;
            if (gcl.getCid() > 0 && this.collectInformation) {
                cellLocations.add(new CellLocationItem(new CellInfoPreV18(gcl)));
            }
        }

        fullInfo.setProperty("TELEPHONY_NETWORK_OPERATOR_NAME",
                String.valueOf(telManager.getNetworkOperatorName()));
        String networkOperator = telManager.getNetworkOperator();
        if (networkOperator != null && networkOperator.length() >= 5)
            networkOperator = String.format("%s-%s", networkOperator.substring(0, 3),
                    networkOperator.substring(3));
        fullInfo.setProperty("TELEPHONY_NETWORK_OPERATOR", String.valueOf(networkOperator));
        fullInfo.setProperty("TELEPHONY_NETWORK_COUNTRY", String.valueOf(telManager.getNetworkCountryIso()));
        fullInfo.setProperty("TELEPHONY_NETWORK_SIM_COUNTRY", String.valueOf(telManager.getSimCountryIso()));
        String simOperator = telManager.getSimOperator();
        if (simOperator != null && simOperator.length() >= 5)
            simOperator = String.format("%s-%s", simOperator.substring(0, 3), simOperator.substring(3));
        fullInfo.setProperty("TELEPHONY_NETWORK_SIM_OPERATOR", String.valueOf(simOperator));

        try // hack for Motorola Defy (#594)
        {
            fullInfo.setProperty("TELEPHONY_NETWORK_SIM_OPERATOR_NAME",
                    String.valueOf(telManager.getSimOperatorName()));
        } catch (SecurityException e) {
            e.printStackTrace();
            fullInfo.setProperty("TELEPHONY_NETWORK_SIM_OPERATOR_NAME", "s.exception");
        }

        fullInfo.setProperty("TELEPHONY_PHONE_TYPE", String.valueOf(telManager.getPhoneType()));

        try // some devices won't allow this w/o READ_PHONE_STATE. conflicts with Android API doc
        {
            fullInfo.setProperty("TELEPHONY_DATA_STATE", String.valueOf(telManager.getDataState()));
        } catch (SecurityException e) {
            e.printStackTrace();
            fullInfo.setProperty("TELEPHONY_DATA_STATE", "s.exception");
        }
        // telManager.listen(telListener,
        // PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
    }
}