Example usage for android.content Context TELEPHONY_SERVICE

List of usage examples for android.content Context TELEPHONY_SERVICE

Introduction

In this page you can find the example usage for android.content Context TELEPHONY_SERVICE.

Prototype

String TELEPHONY_SERVICE

To view the source code for android.content Context TELEPHONY_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.telephony.TelephonyManager for handling management the telephony features of the device.

Usage

From source file:com.nextgis.mobile.DataSendService.java

@Override
public void onCreate() {
    Log.d(MainActivity.TAG, "onCreate()");
    super.onCreate();

    dbHelper = new PositionDatabase(getApplicationContext());
    PositionDB = dbHelper.getWritableDatabase();

    cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
}

From source file:fr.inria.ucn.collectors.NetworkStateCollector.java

/**
 * /* w  w w .  jav  a  2 s  . c  o  m*/
 * @param c
 * @param ts
 * @param change
 */
@SuppressWarnings("deprecation")
@SuppressLint({ "DefaultLocale", "NewApi" })
public void run(Context c, long ts, boolean change) {
    try {
        // current active interface (wifi or mobile) and config
        ConnectivityManager cm = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
        TelephonyManager tm = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE);
        NetworkInfo ni = cm.getActiveNetworkInfo();

        JSONObject data = new JSONObject();
        data.put("on_network_state_change", change); // this collection run was triggered by network change
        data.put("is_connected", (ni != null && ni.isConnectedOrConnecting()));
        data.put("is_roaming", tm.isNetworkRoaming());

        // airplane mode ?
        if (android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.JELLY_BEAN) {
            data.put("is_airplane_mode",
                    (Settings.System.getInt(c.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) != 0));
        } else {
            data.put("is_airplane_mode",
                    (Settings.Global.getInt(c.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0));
        }

        if (ni != null) {
            JSONObject active = new JSONObject();
            active.put("type", ni.getType());
            active.put("subtype", ni.getSubtype());
            active.put("type_name", ni.getTypeName());
            active.put("subtype_name", ni.getSubtypeName());
            active.put("state", ni.getState().toString());
            active.put("detailed_state", ni.getDetailedState().toString());
            active.put("is_wifi", (ni.getType() == ConnectivityManager.TYPE_WIFI));
            data.put("active_network", active);

            if (ni.getType() == ConnectivityManager.TYPE_WIFI) {
                data.put("wifi_network", getWifi(c));
            }
        }

        // mobile network details
        data.put("mobile_network", getMobile(tm));

        // kernel network statistics
        data.put("netstat", getNetstat());

        // interfaces config
        Map<String, JSONObject> stats = networkStats();
        data.put("ifconfig", getIfconfig(stats));

        // double check interfaces
        data.put("ip_addr_show", getIpAddr(stats));

        Helpers.sendResultObj(c, "network_state", ts, data);

    } catch (JSONException jex) {
        Log.w(Constants.LOGTAG, "failed to create json object", jex);
    }
}

From source file:com.tingtingapps.securesms.mms.LegacyMmsConnection.java

protected boolean isCdmaDevice() {
    return ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE))
            .getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA;
}

From source file:com.frame.network.utils.NetworkUtil.java

@TargetApi(11)
public static boolean is4GNetwork(Context cxt) {
    boolean isOpened4G = false;
    TelephonyManager telephonyManager = (TelephonyManager) cxt.getSystemService(Context.TELEPHONY_SERVICE);
    if (Build.VERSION.SDK_INT >= 11) {
        isOpened4G = telephonyManager.getNetworkType() == TelephonyManager.NETWORK_TYPE_LTE;
    }/*  www . j  a  va 2 s .  c o  m*/
    boolean isMobile = false;
    ConnectivityManager cm = (ConnectivityManager) cxt.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    isMobile = info == null ? false : info.isConnected();
    return isOpened4G && isMobile;
}

From source file:com.phonegap.Device.java

public String getLine1Number() {
    TelephonyManager operator = (TelephonyManager) this.ctx.getSystemService(Context.TELEPHONY_SERVICE);
    return operator.getLine1Number();
}

From source file:de.inhji.cordova.plugin.Telephony.java

/**
 * Ruft den Mobilfunkanbieter ab//from   w  w w .j  a  va 2 s.c om
 */
private void getCarrier(CallbackContext ctx) {
    Context context = this.cordova.getActivity().getApplicationContext();
    TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String carrierName = manager.getNetworkOperatorName();

    PluginResult result = new PluginResult(PluginResult.Status.OK, carrierName);
    ctx.sendPluginResult(result);
}

From source file:com.phonegap.Device.java

public String getDeviceId() {
    TelephonyManager operator = (TelephonyManager) this.ctx.getSystemService(Context.TELEPHONY_SERVICE);
    return operator.getDeviceId();
}

From source file:org.wso2.emm.agent.services.DeviceInfoPayload.java

/**
 * Fetch all device runtime information.
 * @throws AndroidAgentException//w  w  w .j a  va  2s.c  om
 */
private void getInfo() throws AndroidAgentException {

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

    Location deviceLocation = locationService.getLastKnownLocation();
    if (device == null) {
        device = new Device();
    }
    deviceInfo = new DeviceInfo(context);
    Power power = phoneState.getBatteryDetails();
    device.setDeviceIdentifier(deviceInfo.getDeviceId());
    device.setDescription(deviceInfo.getDeviceName());
    device.setName(deviceInfo.getDeviceName());

    List<Device.Property> properties = new ArrayList<>();

    Device.Property property = new Device.Property();
    property.setName(Constants.Device.SERIAL);
    property.setValue(deviceInfo.getDeviceSerialNumber());
    properties.add(property);

    property = new Device.Property();
    property.setName(Constants.Device.IMEI);
    property.setValue(telephonyManager.getDeviceId());
    properties.add(property);

    property = new Device.Property();
    property.setName(Constants.Device.IMSI);
    property.setValue(deviceInfo.getIMSINumber());
    properties.add(property);

    property = new Device.Property();
    property.setName(Constants.Device.MAC);
    property.setValue(deviceInfo.getMACAddress());
    properties.add(property);

    property = new Device.Property();
    property.setName(Constants.Device.MODEL);
    property.setValue(deviceInfo.getDeviceModel());
    properties.add(property);

    property = new Device.Property();
    property.setName(Constants.Device.VENDOR);
    property.setValue(deviceInfo.getDeviceManufacturer());
    properties.add(property);

    property = new Device.Property();
    property.setName(Constants.Device.OS);
    property.setValue(deviceInfo.getOsVersion());
    properties.add(property);

    property = new Device.Property();
    property.setName(Constants.Device.OS_BUILD_DATE);
    property.setValue(deviceInfo.getOSBuildDate());
    properties.add(property);

    property = new Device.Property();
    property.setName(Constants.Device.NAME);
    property.setValue(deviceInfo.getDeviceName());
    properties.add(property);

    if (deviceLocation != null) {
        double latitude = deviceLocation.getLatitude();
        double longitude = deviceLocation.getLongitude();

        if (latitude != 0 && longitude != 0) {
            property = new Device.Property();
            property.setName(Constants.Device.MOBILE_DEVICE_LATITUDE);
            property.setValue(String.valueOf(latitude));
            properties.add(property);

            property = new Device.Property();
            property.setName(Constants.Device.MOBILE_DEVICE_LONGITUDE);
            property.setValue(String.valueOf(longitude));
            properties.add(property);
        }
    }

    if (registrationId != null) {
        property = new Device.Property();
        property.setName(Constants.Device.GCM_TOKEN);
        property.setValue(registrationId);
        properties.add(property);
    }

    List<Device.Property> deviceInfoProperties = new ArrayList<>();

    property = new Device.Property();
    property.setName(Constants.Device.ENCRYPTION_STATUS);
    property.setValue(String.valueOf(deviceInfo.isEncryptionEnabled()));
    deviceInfoProperties.add(property);

    if ((deviceInfo.getSdkVersion() >= Build.VERSION_CODES.LOLLIPOP)) {
        property = new Device.Property();
        property.setName(Constants.Device.PASSCODE_STATUS);
        property.setValue(String.valueOf(deviceInfo.isPasscodeEnabled()));
        deviceInfoProperties.add(property);
    }

    property = new Device.Property();
    property.setName(Constants.Device.BATTERY_LEVEL);
    int batteryLevel = Math.round(power.getLevel());
    property.setValue(String.valueOf(batteryLevel));
    deviceInfoProperties.add(property);

    property = new Device.Property();
    property.setName(Constants.Device.MEMORY_INFO_INTERNAL_TOTAL);
    property.setValue(String.valueOf(phoneState.getTotalInternalMemorySize()));
    deviceInfoProperties.add(property);

    property = new Device.Property();
    property.setName(Constants.Device.MEMORY_INFO_INTERNAL_AVAILABLE);
    property.setValue(String.valueOf(phoneState.getAvailableInternalMemorySize()));
    deviceInfoProperties.add(property);

    property = new Device.Property();
    property.setName(Constants.Device.MEMORY_INFO_EXTERNAL_TOTAL);
    property.setValue(String.valueOf(phoneState.getTotalExternalMemorySize()));
    deviceInfoProperties.add(property);

    property = new Device.Property();
    property.setName(Constants.Device.MEMORY_INFO_EXTERNAL_AVAILABLE);
    property.setValue(String.valueOf(phoneState.getAvailableExternalMemorySize()));
    deviceInfoProperties.add(property);

    property = new Device.Property();
    property.setName(Constants.Device.NETWORK_OPERATOR);
    property.setValue(String.valueOf(deviceInfo.getNetworkOperatorName()));
    deviceInfoProperties.add(property);

    property = new Device.Property();
    property.setName(Constants.Device.PHONE_NUMBER);
    String mPhoneNumber = telephonyManager.getLine1Number();
    property.setValue(mPhoneNumber);
    deviceInfoProperties.add(property);

    DeviceNetworkStatus deviceNetworkStatus = DeviceNetworkStatus.getInstance(context);
    if (deviceNetworkStatus.isConnectedMobile()) {
        telephonyManager.listen(deviceNetworkStatus, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
    }

    String network = deviceNetworkStatus.getNetworkStatus();
    if (network != null) {
        property = new Device.Property();
        property.setName(Constants.Device.NETWORK_INFO);
        property.setValue(network);
        properties.add(property);
    }

    // adding wifi scan results..
    property = new Device.Property();
    property.setName(Constants.Device.WIFI_SCAN_RESULT);
    property.setValue(deviceNetworkStatus.getWifiScanResult());
    properties.add(property);

    RuntimeInfo runtimeInfo = new RuntimeInfo(context);
    String cpuInfoPayload;
    try {
        cpuInfoPayload = mapper.writeValueAsString(runtimeInfo.getCPUInfo());
    } catch (JsonProcessingException e) {
        String errorMsg = "Error occurred while parsing property CPU info object to json.";
        Log.e(TAG, errorMsg, e);
        throw new AndroidAgentException(errorMsg, e);
    }

    property = new Device.Property();
    property.setName(Constants.Device.CPU_INFO);
    property.setValue(cpuInfoPayload);
    properties.add(property);

    String ramInfoPayload;
    try {
        ramInfoPayload = mapper.writeValueAsString(runtimeInfo.getRAMInfo());
    } catch (JsonProcessingException e) {
        String errorMsg = "Error occurred while parsing property RAM info object to json.";
        Log.e(TAG, errorMsg, e);
        throw new AndroidAgentException(errorMsg, e);
    }

    property = new Device.Property();
    property.setName(Constants.Device.RAM_INFO);
    property.setValue(ramInfoPayload);
    properties.add(property);

    List<Device.Property> batteryProperties = new ArrayList<>();
    property = new Device.Property();
    property.setName(Constants.Device.BATTERY_LEVEL);
    property.setValue(String.valueOf(power.getLevel()));
    batteryProperties.add(property);

    property = new Device.Property();
    property.setName(Constants.Device.SCALE);
    property.setValue(String.valueOf(power.getScale()));
    batteryProperties.add(property);

    property = new Device.Property();
    property.setName(Constants.Device.BATTERY_VOLTAGE);
    property.setValue(String.valueOf(power.getVoltage()));
    batteryProperties.add(property);

    property = new Device.Property();
    property.setName(Constants.Device.HEALTH);
    property.setValue(String.valueOf(power.getHealth()));
    batteryProperties.add(property);

    property = new Device.Property();
    property.setName(Constants.Device.STATUS);
    property.setValue(String.valueOf(power.getStatus()));
    batteryProperties.add(property);

    property = new Device.Property();
    property.setName(Constants.Device.PLUGGED);
    property.setValue(String.valueOf(power.getPlugged()));
    batteryProperties.add(property);

    String batteryInfoPayload;
    try {
        batteryInfoPayload = mapper.writeValueAsString(batteryProperties);
    } catch (JsonProcessingException e) {
        String errorMsg = "Error occurred while parsing property battery info object to json.";
        Log.e(TAG, errorMsg, e);
        throw new AndroidAgentException(errorMsg, e);
    }

    property = new Device.Property();
    property.setName(Constants.Device.BATTERY_INFO);
    property.setValue(batteryInfoPayload);
    properties.add(property);

    // building device info json payload
    String deviceInfoPayload;
    try {
        deviceInfoPayload = mapper.writeValueAsString(deviceInfoProperties);
    } catch (JsonProcessingException e) {
        String errorMsg = "Error occurred while parsing property object to json.";
        Log.e(TAG, errorMsg, e);
        throw new AndroidAgentException(errorMsg, e);
    }
    property = new Device.Property();
    property.setName(Constants.Device.INFO);
    property.setValue(deviceInfoPayload);
    properties.add(property);

    device.setProperties(properties);
}

From source file:com.phonegap.Device.java

public String getSimSerialNumber() {
    TelephonyManager operator = (TelephonyManager) this.ctx.getSystemService(Context.TELEPHONY_SERVICE);
    return operator.getSimSerialNumber();
}