Example usage for android.telephony TelephonyManager DATA_ACTIVITY_INOUT

List of usage examples for android.telephony TelephonyManager DATA_ACTIVITY_INOUT

Introduction

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

Prototype

int DATA_ACTIVITY_INOUT

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

Click Source Link

Document

Data connection activity: Currently both sending and receiving IP PPP traffic.

Usage

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

/** Called when the activity is first created. */
@Override/*from  w  w w.ja  v a2s  . c  o m*/
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:org.restcomm.app.qoslib.Services.LibPhoneStateListener.java

@Override
public void onDataActivity(int data) {
    super.onDataActivity(data);
    if (owner.getUsageLimits().getDormantMode() > 0)
        return;//from   ww  w . j  a va 2 s.com
    String activity = null;
    try {
        activity = owner.getConnectionHistory().updateConnectionHistory(telephonyManager.getNetworkType(),
                telephonyManager.getDataState(), telephonyManager.getDataActivity(),
                mPhoneState.previousServiceStateObj, owner.getConnectivityManager().getActiveNetworkInfo());
    } catch (Exception e) {
        LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "onDataActivity", "ex " + e.getMessage());
    }
    if (data == TelephonyManager.DATA_ACTIVITY_IN || data == TelephonyManager.DATA_ACTIVITY_INOUT) {
        if (activity != null) {
            owner.getIntentDispatcher().updateConnection(activity, true);
        }
        //User allows - default yes
        if (PreferenceManager.getDefaultSharedPreferences(owner)
                .getBoolean(PreferenceKeys.User.PASSIVE_SPEED_TEST, true) || Global.SCANAPP_PERIOD > 0) {
            //Don't allow if a speedtest is in progress
            if (PreferenceManager.getDefaultSharedPreferences(owner)
                    .getBoolean(PreferenceKeys.Miscellaneous.SPEEDTEST_INPROGRESS, false)) {
                return;
            }
            if (PreferenceManager.getDefaultSharedPreferences(owner)
                    .getBoolean(PreferenceKeys.Miscellaneous.VIDEOTEST_INPROGRESS, false)) {
                return;
            }
            //if (owner.getUsageLimits().getUsageProfile () == UsageLimits.MINIMAL)
            //   return;
            //server allows - default no
            int allow = PreferenceManager.getDefaultSharedPreferences(owner)
                    .getInt(PreferenceKeys.Miscellaneous.PASSIVE_SPEEDTEST_SERVER, 0);
            if (!EventObj.isDisabledStat(owner, EventObj.DISABLESTAT_APPS_THROUGHPUT)
                    && Global.SCANAPP_PERIOD > 0)
                allow = 1;
            if (allow > 0) {
                dataThrougput();
            }
        }
    } else {
        if (activity != null) {
            owner.getIntentDispatcher().updateConnection(activity, false);
        }
    }

}

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

public String getActivityName(int activity) {
    switch (activity) {
    case TelephonyManager.DATA_ACTIVITY_DORMANT:
        return context.getString(R.string.LiveStatus_dormant);
    case TelephonyManager.DATA_ACTIVITY_IN:
        return context.getString(R.string.LiveStatus_receiving);
    case TelephonyManager.DATA_ACTIVITY_OUT:
        return context.getString(R.string.LiveStatus_sending);
    case TelephonyManager.DATA_ACTIVITY_INOUT:
        return context.getString(R.string.LiveStatus_sendrecv);
    case TelephonyManager.DATA_ACTIVITY_NONE:
        return context.getString(R.string.LiveStatus_noactivty);

    }// w  ww.j  av a 2s  .c  om
    return "U";
}