Java Code Examples for android.telephony.TelephonyManager#DATA_CONNECTED

The following examples show how to use android.telephony.TelephonyManager#DATA_CONNECTED . 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: DataConnectionStats.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void notePhoneDataConnectionState() {
    if (mServiceState == null) {
        return;
    }
    boolean simReadyOrUnknown = mSimState == IccCardConstants.State.READY
            || mSimState == IccCardConstants.State.UNKNOWN;
    boolean visible = (simReadyOrUnknown || isCdma()) // we only check the sim state for GSM
            && hasService()
            && mDataState == TelephonyManager.DATA_CONNECTED;
    int networkType = mServiceState.getDataNetworkType();
    if (DEBUG) Log.d(TAG, String.format("Noting data connection for network type %s: %svisible",
            networkType, visible ? "" : "not "));
    try {
        mBatteryStats.notePhoneDataConnectionState(networkType, visible);
    } catch (RemoteException e) {
        Log.w(TAG, "Error noting data connection state", e);
    }
}
 
Example 2
Source File: Device.java    From AIMSICDL with GNU General Public License v3.0 6 votes vote down vote up
String getDataState(TelephonyManager tm) {
    int state = tm.getDataState();
    mDataState = "undef";
    mDataStateShort = "un";
    switch (state) {
        case TelephonyManager.DATA_DISCONNECTED:
            mDataState = "Disconnected";
            mDataStateShort = "Di";
            break;
        case TelephonyManager.DATA_CONNECTING:
            mDataState = "Connecting";
            mDataStateShort = "Ct";
            break;
        case TelephonyManager.DATA_CONNECTED:
            mDataState = "Connected";
            mDataStateShort = "Cd";
            break;
        case TelephonyManager.DATA_SUSPENDED:
            mDataState = "Suspended";
            mDataStateShort = "Su";
            break;
    }

    return mDataState;
}
 
Example 3
Source File: CellTracker.java    From AIMSICDL with GNU General Public License v3.0 6 votes vote down vote up
public void onDataConnectionStateChanged(int state) {
    switch (state) {
        case TelephonyManager.DATA_DISCONNECTED:
            mDevice.setDataState("Disconnected");
            mDevice.setDataStateShort("Di");
            break;
        case TelephonyManager.DATA_CONNECTING:
            mDevice.setDataState("Connecting");
            mDevice.setDataStateShort("Ct");
            break;
        case TelephonyManager.DATA_CONNECTED:
            mDevice.setDataState("Connected");
            mDevice.setDataStateShort("Cd");
            break;
        case TelephonyManager.DATA_SUSPENDED:
            mDevice.setDataState("Suspended");
            mDevice.setDataStateShort("Su");
            break;
    }
}
 
Example 4
Source File: Network.java    From batteryhub with Apache License 2.0 6 votes vote down vote up
public static String getDataState(Context context) {
    TelephonyManager manager = (TelephonyManager)
            context.getSystemService(Context.TELEPHONY_SERVICE);

    int dataState = manager.getDataState();

    switch (dataState) {
        case TelephonyManager.DATA_CONNECTED:
            return DATA_CONNECTED;
        case TelephonyManager.DATA_CONNECTING:
            return DATA_CONNECTING;
        case TelephonyManager.DATA_DISCONNECTED:
            return DATA_DISCONNECTED;
        default:
            return DATA_SUSPENDED;
    }
}
 
Example 5
Source File: NetworkUtil.java    From NIM_Android_UIKit with MIT License 6 votes vote down vote up
public static boolean getNetworkConnectionStatus(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (manager == null) {
        return false;
    }

    NetworkInfo info = manager.getActiveNetworkInfo();
    if (info == null) {
        return false;
    }

    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (tm == null) {
        return false;
    }

    if ((tm.getDataState() == TelephonyManager.DATA_CONNECTED || tm.getDataState() == TelephonyManager.DATA_ACTIVITY_NONE)
            && info.isAvailable()) {
        return true;
    } else {
        return false;
    }
}
 
Example 6
Source File: SanaUtil.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Returns true if the phone has telphony or wifi service
 *
 * @param c - The current context
 * @return true if Android has either a wifi or cellular connection active
 */
public static boolean checkConnection(Context c) {
    try {
        TelephonyManager telMan = (TelephonyManager) c.getSystemService(
                Context.TELEPHONY_SERVICE);
        WifiManager wifiMan = (WifiManager) c.getSystemService(
                Context.WIFI_SERVICE);

        if (telMan != null && wifiMan != null) {
            int dataState = telMan.getDataState();
            if (dataState == TelephonyManager.DATA_CONNECTED ||
                    (wifiMan.isWifiEnabled() && wifiMan.pingSupplicant()))
                return true;
        }

        return false;
    } catch (Exception e) {
        Log.e(TAG, "Exception in checkConnection(): " + e.toString());
        return false;
    }
}
 
Example 7
Source File: TrafficMeterAbstract.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
protected TrafficMeterAbstract(Context context) {
    super(context);

    LinearLayout.LayoutParams lParams = new LinearLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
    mMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2,
            context.getResources().getDisplayMetrics());
    lParams.setMarginStart(mMargin);
    lParams.setMarginEnd(mMargin);
    setLayoutParams(lParams);
    setTextAppearance(context.getResources().getIdentifier(
            "TextAppearance.StatusBar.Clock", "style", PACKAGE_NAME));
    setGravity(Gravity.END | Gravity.CENTER_VERTICAL);

    if (!Utils.isWifiOnly(getContext())) {
        mPhone = (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE);
        mPhoneStateListener = new PhoneStateListener() {
            @Override
            public void onDataConnectionStateChanged(int state, int networkType) {
                final boolean connected = state == TelephonyManager.DATA_CONNECTED;
                if (mMobileDataConnected != connected) {
                    mMobileDataConnected = connected;
                    if (DEBUG)
                        log("onDataConnectionStateChanged: mMobileDataConnected=" + mMobileDataConnected);
                    updateState();
                }

            }
        };
    }
}
 
Example 8
Source File: DataIconData.java    From Status with Apache License 2.0 5 votes vote down vote up
private void onDataChanged() {
    switch (telephonyManager.getDataState()) {
        case TelephonyManager.DATA_CONNECTED:
        case TelephonyManager.DATA_CONNECTING:
            if (telephonyManager.getDataState() != TelephonyManager.DATA_DISCONNECTED) {
                switch (telephonyManager.getNetworkType()) {
                    case TelephonyManager.NETWORK_TYPE_GPRS:
                    case TelephonyManager.NETWORK_TYPE_EDGE:
                    case TelephonyManager.NETWORK_TYPE_IDEN:
                        onTextUpdate("2G");
                        return;
                    case TelephonyManager.NETWORK_TYPE_UMTS:
                    case TelephonyManager.NETWORK_TYPE_HSDPA:
                    case TelephonyManager.NETWORK_TYPE_HSUPA:
                    case TelephonyManager.NETWORK_TYPE_EVDO_0:
                    case TelephonyManager.NETWORK_TYPE_EVDO_A:
                    case TelephonyManager.NETWORK_TYPE_EVDO_B:
                    case TelephonyManager.NETWORK_TYPE_EHRPD:
                    case TelephonyManager.NETWORK_TYPE_CDMA:
                    case TelephonyManager.NETWORK_TYPE_1xRTT:
                        onTextUpdate("3G");
                        return;
                    case TelephonyManager.NETWORK_TYPE_HSPA:
                        onTextUpdate("H");
                        return;
                    case TelephonyManager.NETWORK_TYPE_HSPAP:
                        onTextUpdate("H+");
                        return;
                    case TelephonyManager.NETWORK_TYPE_LTE:
                        onTextUpdate("4G");
                        return;
                }
            }
    }

    onTextUpdate(null);
}
 
Example 9
Source File: NetworkStateMonitor.java    From LibreTasks with Apache License 2.0 5 votes vote down vote up
@Override
public void onDataConnectionStateChanged(int state){
  if (state == TelephonyManager.DATA_CONNECTED) {
    if (!wifiConnected) {
      Intent intent = new Intent(InternetAvailableEvent.ACTION_NAME);
      context.sendBroadcast(intent);
    }
    // If phone was using wifi then it's not a new InternetAvailable event
    dataConnected = true;
  } else {
    dataConnected = false;
  }
}
 
Example 10
Source File: PhoneStateChangeListener.java    From androidpn-client with Apache License 2.0 5 votes vote down vote up
@Override
public void onDataConnectionStateChanged(int state) {
    super.onDataConnectionStateChanged(state);
    Log.d(LOGTAG, "onDataConnectionStateChanged()...");
    Log.d(LOGTAG, "Data Connection State = " + getState(state));
    
    if (state == TelephonyManager.DATA_CONNECTED) {
        notificationService.connect();
    }
}
 
Example 11
Source File: PhoneStateChangeListener.java    From AndroidPNClient with Apache License 2.0 5 votes vote down vote up
@Override
public void onDataConnectionStateChanged(int state) {
    super.onDataConnectionStateChanged(state);
    Log.d(LOGTAG, "onDataConnectionStateChanged()...");
    Log.d(LOGTAG, "Data Connection State = " + getState(state));
    
    if (state == TelephonyManager.DATA_CONNECTED) {
        BroadcastUtil.sendBroadcast(notificationService, BroadcastUtil.APN_ACTION_RECONNECT);
    }
}
 
Example 12
Source File: BackgroundUploader.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onDataConnectionStateChanged(int state) {
    if (state == TelephonyManager.DATA_CONNECTED) {
        Log.i("TAG", "Data is now connected");
    } else {
        Log.i("TAG", "Data is now disconnected");
    }
    // Tell the BackgroundUploader the data connection state changed.
    BackgroundUploader.this.onConnectionChanged();
}
 
Example 13
Source File: PhoneStateChangeListener.java    From android-demo-xmpp-androidpn with Apache License 2.0 5 votes vote down vote up
@Override
public void onDataConnectionStateChanged(int state) {
    super.onDataConnectionStateChanged(state);
    Log.d(LOGTAG, "onDataConnectionStateChanged()...");
    Log.d(LOGTAG, "Data Connection State = " + getState(state));
    
    if (state == TelephonyManager.DATA_CONNECTED) {
        notificationService.connect();  //这里又连接了一次服务器
    }
}