Example usage for android.telephony TelephonyManager DATA_DISCONNECTED

List of usage examples for android.telephony TelephonyManager DATA_DISCONNECTED

Introduction

In this page you can find the example usage for android.telephony TelephonyManager DATA_DISCONNECTED.

Prototype

int DATA_DISCONNECTED

To view the source code for android.telephony TelephonyManager DATA_DISCONNECTED.

Click Source Link

Document

Data connection state: Disconnected.

Usage

From source file:com.ultrafunk.network_info.service.MobileDataStateListener.java

@Override
public void onDataConnectionStateChanged(int state) {
    switch (state) {
    case TelephonyManager.DATA_CONNECTED:
    case TelephonyManager.DATA_DISCONNECTED:
        LocalBroadcastManager.getInstance(context)
                .sendBroadcast(new Intent(Constants.ACTION_DATA_CONNECTION_CHANGED));
        break;//  w w w. j a v a2s.c om
    }
}

From source file:com.karpenstein.signalmon.SignalMonitorActivity.java

/** Called when the activity is first created. */
@Override//from   www.  j  av a  2  s  . c om
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Get the UI
    textOut = (TextView) findViewById(R.id.textOut);

    // Get the telephony manager
    telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

    // Create a new PhoneStateListener
    listener = new PhoneStateListener() {
        @Override
        public void onDataActivity(int direction) {
            String dirString = "N/A";
            switch (direction) {
            case TelephonyManager.DATA_ACTIVITY_NONE:
                dirString = "DATA_ACTIVITY_NONE";
                break;
            case TelephonyManager.DATA_ACTIVITY_IN:
                dirString = "DATA_ACTIVITY_IN";
                break;
            case TelephonyManager.DATA_ACTIVITY_OUT:
                dirString = "DATA_ACTIVITY_OUT";
                break;
            case TelephonyManager.DATA_ACTIVITY_INOUT:
                dirString = "DATA_ACTIVITY_INOUT";
                break;
            case TelephonyManager.DATA_ACTIVITY_DORMANT:
                dirString = "DATA_ACTIVITY_DORMANT";
                break;
            }
            textOut.append(dirString + "\n");
        }

        @Override
        public void onSignalStrengthsChanged(SignalStrength signalStrength) {
            textOut.append(signalStrength.toString() + "\n");
        }

        @Override
        public void onDataConnectionStateChanged(int state, int networkType) {
            String stateString = "N/A";
            String netTypString = "N/A";
            switch (state) {
            case TelephonyManager.DATA_CONNECTED:
                stateString = "DATA_CONNECTED";
                break;
            case TelephonyManager.DATA_CONNECTING:
                stateString = "DATA_CONNECTING";
                break;
            case TelephonyManager.DATA_DISCONNECTED:
                stateString = "DATA_DISCONNECTED";
                break;
            case TelephonyManager.DATA_SUSPENDED:
                stateString = "DATA_SUSPENDED";
                break;
            }
            switch (networkType) {
            case TelephonyManager.NETWORK_TYPE_1xRTT:
                netTypString = "NETWORK_TYPE_1xRTT";
                break;
            case TelephonyManager.NETWORK_TYPE_CDMA:
                netTypString = "NETWORK_TYPE_CDMA";
                break;
            case TelephonyManager.NETWORK_TYPE_EDGE:
                netTypString = "NETWORK_TYPE_EDGE";
                break;
            case TelephonyManager.NETWORK_TYPE_EVDO_0:
                netTypString = "NETWORK_TYPE_EVDO_0";
                break;
            case TelephonyManager.NETWORK_TYPE_EVDO_A:
                netTypString = "NETWORK_TYPE_EVDO_A";
                break;
            case TelephonyManager.NETWORK_TYPE_GPRS:
                netTypString = "NETWORK_TYPE_GPRS";
                break;
            case TelephonyManager.NETWORK_TYPE_HSDPA:
                netTypString = "NETWORK_TYPE_HSDPA";
                break;
            case TelephonyManager.NETWORK_TYPE_HSPA:
                netTypString = "NETWORK_TYPE_HSPA";
                break;
            case TelephonyManager.NETWORK_TYPE_HSUPA:
                netTypString = "NETWORK_TYPE_HSUPA";
                break;
            case TelephonyManager.NETWORK_TYPE_IDEN:
                netTypString = "NETWORK_TYPE_IDE";
                break;
            case TelephonyManager.NETWORK_TYPE_UMTS:
                netTypString = "NETWORK_TYPE_UMTS";
                break;
            case TelephonyManager.NETWORK_TYPE_UNKNOWN:
                netTypString = "NETWORK_TYPE_UNKNOWN";
                break;
            }
            textOut.append(String.format("onDataConnectionStateChanged: %s; %s\n", stateString, netTypString));
        }
    };

    // Register the listener with the telephony manager
    telephonyManager.listen(listener, PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
            | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS | PhoneStateListener.LISTEN_DATA_ACTIVITY);

    // start the NetServerService
    startService(new Intent(this, NetServerService.class));
}

From source file:com.fallahpoor.infocenter.fragments.SimFragment.java

private String getDataConnectionState(TelephonyManager telephonyManager) {

    int dataStateInt = telephonyManager.getDataState();
    String dataStateStr;//  www .j a  va  2  s  . co m

    switch (dataStateInt) {
    case TelephonyManager.DATA_CONNECTED:
        dataStateStr = getString(R.string.sim_sub_item_data_connected);
        break;
    case TelephonyManager.DATA_CONNECTING:
        dataStateStr = getString(R.string.sim_sub_item_data_connecting);
        break;
    case TelephonyManager.DATA_DISCONNECTED:
        dataStateStr = getString(R.string.sim_sub_item_data_disconnected);
        break;
    case TelephonyManager.DATA_SUSPENDED:
        dataStateStr = getString(R.string.sim_sub_item_data_suspended);
        break;
    default:
        dataStateStr = getString(R.string.unknown);
    }

    return dataStateStr;

}

From source file:com.ultrafunk.network_info.receiver.MobileDataStatusReceiver.java

@Override
protected void updateView(Context context, RemoteViews remoteViews, Bundle widgetOptions) {
    if (isMobileDataEnabled && isMobileOutOfService) {
        setStateColor(context, remoteViews, STATE_ON);
        remoteViews.setTextViewText(R.id.mobileNameTextView, context.getString(R.string.mobile_data));
        remoteViews.setImageViewResource(R.id.mobileStateImageView, R.drawable.ic_signal_cellular_enabled);
        remoteViews.setViewVisibility(R.id.mobileInfoTopTextView, View.VISIBLE);
        remoteViews.setTextViewText(R.id.mobileInfoTopTextView, context.getString(R.string.no_service));
        remoteViews.setViewVisibility(R.id.mobileInfoBottomTextView, View.GONE);
        return;/*from w  ww.j a  v a  2s  . com*/
    }

    if (dataState == TelephonyManager.DATA_DISCONNECTED) {
        remoteViews.setViewVisibility(R.id.mobileInfoTopTextView, View.VISIBLE);
        remoteViews.setViewVisibility(R.id.mobileInfoBottomTextView, View.VISIBLE);

        if (isMobileDataEnabled && !isAirplaneModeOn) {
            setStateColor(context, remoteViews, STATE_ON);
            remoteViews.setTextViewText(R.id.mobileNameTextView, networkOperatorAndServiceProvider);
            remoteViews.setImageViewResource(R.id.mobileStateImageView, R.drawable.ic_signal_cellular_enabled);
            remoteViews.setTextViewText(R.id.mobileInfoTopTextView, context.getString(R.string.not_connected));
            remoteViews.setTextColor(R.id.mobileInfoBottomTextView,
                    ContextCompat.getColor(context, R.color.medium_gray));
            remoteViews.setTextViewText(R.id.mobileInfoBottomTextView,
                    MobileDataUtils.getDataUsageString(context, NetworkStateService.getDataUsageBytes()));
        } else {
            setStateColor(context, remoteViews, STATE_OFF);
            remoteViews.setTextViewText(R.id.mobileNameTextView,
                    isAirplaneModeOn ? context.getString(R.string.mobile_data)
                            : networkOperatorAndServiceProvider);
            remoteViews.setImageViewResource(R.id.mobileStateImageView, R.drawable.ic_signal_cellular_off);

            if (isAirplaneModeOn) {
                remoteViews.setTextViewText(R.id.mobileInfoTopTextView,
                        context.getString(R.string.flight_mode));
                remoteViews.setViewVisibility(R.id.mobileInfoBottomTextView, View.GONE);
            } else {
                remoteViews.setTextViewText(R.id.mobileInfoTopTextView,
                        MobileDataUtils.getNetworkTypeString(telephonyManager.getNetworkType())
                                + (isDataRoaming ? " - " + context.getString(R.string.roaming) : ""));
                remoteViews.setTextViewText(R.id.mobileInfoBottomTextView,
                        MobileDataUtils.getDataUsageString(context, NetworkStateService.getDataUsageBytes()));
            }
        }
    } else {
        setStateColor(context, remoteViews, STATE_ON);
        remoteViews.setTextViewText(R.id.mobileNameTextView, networkOperatorAndServiceProvider);
        remoteViews.setImageViewResource(R.id.mobileStateImageView, R.drawable.ic_signal_cellular_on);
        remoteViews.setViewVisibility(R.id.mobileInfoTopTextView, View.VISIBLE);
        remoteViews.setTextViewText(R.id.mobileInfoTopTextView,
                MobileDataUtils.getNetworkTypeString(telephonyManager.getNetworkType())
                        + (isDataRoaming ? " - " + context.getString(R.string.roaming) : ""));
        remoteViews.setViewVisibility(R.id.mobileInfoBottomTextView, View.VISIBLE);

        boolean isConnecting = ((dataState == TelephonyManager.DATA_CONNECTING)
                || NetworkStateService.isWaitingForDataUsage());
        remoteViews.setTextViewText(R.id.mobileInfoBottomTextView,
                isConnecting ? context.getString(R.string.connecting)
                        : MobileDataUtils.getDataUsageString(context, dataUsageBytes));
    }
}

From source file:com.compal.telephonytest.TelephonyTest.java

public void InformatonAndStatusCheck() {

    StringBuilder sb = new StringBuilder("");
    boolean hasFailInfo = false;

    if (mTelephonyManager.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE) {
        sb.append("getPhoneType:" + Integer.toString(mTelephonyManager.getPhoneType()) + "\n");
    } else {//  w w  w . jav  a2  s  .  c om
        sb.append("getPhoneType:" + "fail");
        hasFailInfo = true;
    }

    if (mTelephonyManager.getNetworkType() != TelephonyManager.NETWORK_TYPE_UNKNOWN) {
        sb.append("getNetworkType:" + Integer.toString(mTelephonyManager.getNetworkType()) + "\n");
    } else {
        sb.append("getNetworkType:" + "fail");
        hasFailInfo = true;
    }

    String operatorName = mTelephonyManager.getNetworkOperatorName();
    if (operatorName != null && !operatorName.equals("")) { // OperatorName
        sb.append("getNetworkOperatorName:" + mTelephonyManager.getNetworkOperatorName() + "\n");
    } else {
        sb.append("getNetworkOperatorName:" + "fail");
        hasFailInfo = true;
    }

    String serial = Build.SERIAL;
    if (serial != null && !serial.equals("")) { // SerialNumber
        sb.append("get Serial Number:" + serial + "\n");
    } else {
        sb.append("get Serial Number:" + "fail");
        hasFailInfo = true;
    }

    if (mTelephonyManager.getSimState() != TelephonyManager.SIM_STATE_UNKNOWN) {
        sb.append("getSimState:" + Integer.toString(mTelephonyManager.getSimState()) + "\n");
    } else {
        sb.append("getSimState:" + "fail");
        hasFailInfo = true;
    }

    //It's all ok
    sb.append("isNetworkRoaming:" + Boolean.toString(mTelephonyManager.isNetworkRoaming()) + "\n");

    if (mTelephonyManager.getDataState() != TelephonyManager.DATA_DISCONNECTED) {
        sb.append("getDataState:" + Integer.toString(mTelephonyManager.getDataState()) + "\n");
    } else {
        sb.append("getDataState:" + "fail");
        hasFailInfo = true;
    }

    String formatIP = formatIpAddresses(mLinkProperties);
    if (formatIP != null && !formatIP.equals("")) { //IP Address
        sb.append("IP Address:" + formatIpAddresses(mLinkProperties) + "\n");
    } else {
        sb.append("IP Address:" + "fail");
        hasFailInfo = true;
    }

    if (mTelephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) {
        if (checkGsmDeviceId(mTelephonyManager.getDeviceId())) {
            sb.append("IMEI:" + mTelephonyManager.getDeviceId() + "\n");
        } else {
            sb.append("IMEI:" + "fail");
            hasFailInfo = true;
        }
    } else {
        sb.append("IMEI:" + "fail");
        hasFailInfo = true;
    }

    Log.i(tag, sb.toString());

    mLog = sb.toString();
    if (!hasFailInfo) {
        Log.i(tag, "test_5th_InformatonAndStatus true");
        outputResult(true, tTelephonyBasicFunc, dBasicInformation, testCaseId);
    } else {
        Log.i(tag, "test_5th_InformatonAndStatus false");
        outputResult(false, tTelephonyBasicFunc, dBasicInformation, testCaseId);
    }

    //Log.i(tag, "getPhoneType:" + Integer.toString(mTelephonyManager.getPhoneType()));
    //Log.i(tag, "getNetworkType:" + Integer.toString(mTelephonyManager.getNetworkType()));
    //Log.i(tag, "getNetworkOperatorName:" + mTelephonyManager.getNetworkOperatorName());
    //Log.i(tag, "getSimSerialNumber:" + mTelephonyManager.getSimSerialNumber());
    //Log.i(tag, "getSimState:" + Integer.toString(mTelephonyManager.getSimState()));
    //Log.i(tag, "isNetworkRoaming:" + Boolean.toString(mTelephonyManager.isNetworkRoaming()));
    //Log.i(tag, "getDataState:" + Integer.toString(mTelephonyManager.getDataState()));   
    //Log.i(tag,"formatIpAddresses(mLinkProperties): " + formatIpAddresses(mLinkProperties));

}

From source file:org.restcomm.app.qoslib.Utils.QosInfo.java

public String getStateName(int state) {
    switch (state) {
    case TelephonyManager.DATA_CONNECTED:
        return "connected";
    case TelephonyManager.DATA_CONNECTING:
        return "connecting";
    case TelephonyManager.DATA_DISCONNECTED:
        return "disconnected";
    case TelephonyManager.DATA_SUSPENDED:
        return "suspended";
    }/*from   w  w w  .j  ava  2  s  . c  o m*/
    return "-";
}

From source file:com.intel.xdk.device.Device.java

private String getConnection() {
    WifiManager wifiMgr = (WifiManager) activity.getSystemService(Context.WIFI_SERVICE);
    if (wifiMgr.isWifiEnabled() == true) {
        return "wifi";
    }//from w w w  .j a v  a2s .  c o m

    TelephonyManager telMgr = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
    int data = telMgr.getDataState();
    if (data == TelephonyManager.DATA_DISCONNECTED || data == TelephonyManager.DATA_SUSPENDED)
        return "none";
    else
        return "cell";
}

From source file:org.restcomm.app.qoslib.Services.LibPhoneStateListener.java

private void stateChanged_0g(int state) {
    // No such thing as DATA outage event
    EventObj event = null;//  w ww  .j a  v  a  2s . co m
    // DATA Outage defined as switching to and connecting to 1G (GPRS) from > 1G (EDGE or higher)
    if (state == TelephonyManager.DATA_DISCONNECTED && mPhoneState.previousNetworkTier > 0) {
        //event = owner.startPhoneEvent(EventType.COV_DATA_DISC, EventType.COV_DATA_CONN);
        // 4G Outage defined as switching to and connecting to 2G from 4G
        if (mPhoneState.previousNetworkTier > 4) {
            if (mPhoneState.isScreenOn() || mPhoneState.isOffHook() || owner.isTravelling())
                event = owner.getEventManager().startPhoneEvent(EventType.COV_4G_NO, EventType.COV_4G_YES);
        }
        if (mPhoneState.previousNetworkTier > 2) {
            if (mPhoneState.isScreenOn() || mPhoneState.isOffHook() || owner.isTravelling())
                event = owner.getEventManager().startPhoneEvent(EventType.COV_3G_NO, EventType.COV_3G_YES);
        }
        if (mPhoneState.previousNetworkTier > 0) {
            if (mPhoneState.isScreenOn() || mPhoneState.isOffHook() || owner.isTravelling())
                event = owner.getEventManager().startPhoneEvent(EventType.COV_DATA_NO, EventType.COV_DATA_YES);
        }
    }

}