Example usage for android.net ConnectivityManager CONNECTIVITY_ACTION

List of usage examples for android.net ConnectivityManager CONNECTIVITY_ACTION

Introduction

In this page you can find the example usage for android.net ConnectivityManager CONNECTIVITY_ACTION.

Prototype

String CONNECTIVITY_ACTION

To view the source code for android.net ConnectivityManager CONNECTIVITY_ACTION.

Click Source Link

Document

A change in network connectivity has occurred.

Usage

From source file:net.ustyugov.jtalk.service.JTalkService.java

@Override
public void onCreate() {
    configure();//from w w w  .j  a v a  2  s  . c o  m
    js = this;
    prefs = PreferenceManager.getDefaultSharedPreferences(this);
    iconPicker = new IconPicker(this);

    //        updateReceiver = new BroadcastReceiver() {
    //         @Override
    //         public void onReceive(Context arg0, Intent arg1) {
    //            updateWidget();
    //         }
    //        };
    //        registerReceiver(updateReceiver, new IntentFilter(Constants.UPDATE));

    connectionReceiver = new ChangeConnectionReceiver();
    registerReceiver(connectionReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));

    screenStateReceiver = new ScreenStateReceiver();
    registerReceiver(new ScreenStateReceiver(), new IntentFilter(Intent.ACTION_SCREEN_ON));
    registerReceiver(new ScreenStateReceiver(), new IntentFilter(Intent.ACTION_SCREEN_OFF));

    Intent i = new Intent(this, RosterActivity.class);
    i.setAction(Intent.ACTION_MAIN);
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
    mBuilder.setSmallIcon(R.drawable.stat_offline);
    mBuilder.setContentTitle(getString(R.string.app_name));
    mBuilder.setContentIntent(contentIntent);

    startForeground(Notify.NOTIFICATION, mBuilder.build());

    WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "jTalk");
    PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "jTalk");

    started = true;

    Cursor cursor = getContentResolver().query(JTalkProvider.ACCOUNT_URI, null,
            AccountDbHelper.ENABLED + " = '" + 1 + "'", null, null);
    if (cursor != null && cursor.getCount() > 0) {
        connect();
        cursor.close();
    }
}

From source file:com.ubiLive.GameCloud.Browser.WebBrowser.java

/** register boradcast*/
private void registerBoradcast() {
    IntentFilter intentfilter = new IntentFilter();
    intentfilter.addAction(Constants.RECEIVER_BROADCAST);
    intentfilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    intentfilter.addAction(Intent.ACTION_SCREEN_OFF);
    intentfilter.addAction(Intent.ACTION_SCREEN_ON);
    boradcastListener = new BroadcastReceiver() {
        @Override// w ww  . ja  v a  2s .  c  o m
        public void onReceive(Context context, Intent intent) {

            DebugLog.d(TAG, "WebViewActivity onReceive");
            DebugLog.e(TAG, "BroadcastReceiver action = " + intent.getAction());
            if (intent.getAction().equalsIgnoreCase(Constants.RECEIVER_BROADCAST)) {
                Bundle bundle = intent.getExtras();
                int msgtype = bundle.getInt("msgtype");
                String msgcontent = bundle.getString("msgcontent");
                DebugLog.d(TAG, "handleMessage...... msgtype=" + msgtype + ", msgcontent=" + msgcontent);
                switch (msgtype) {
                case NotifyManagement.UP_PROBE_BAD_NETWORK:
                    //irtsp 1.12 , WebBrowser is not need to handler the UP_PROBE_BAD_NETWORK event message.
                    /*DebugLog.d(TAG, "UP_PROBE_BAD_NETWORK");
                    mPoorProbingresultFlag = true;
                    mPlayer.bitrate_stopProbe();
                    notifyProbingCompleted(true);*/
                    break;
                case NotifyManagement.UP_PROBE_EXIT:// callback disconnectCB = 6 when bandwidth probe
                    // success. Up_ui_gc.h
                    DebugLog.d(TAG, "GameActivity.m_player.bitrate_stopProbe()");
                    //notifyProbingCompleted(true);
                    /*if(bExitWaitProbeDone){
                       new Timer().schedule(new LogoutTimer(), 100);
                    }*/
                    break;
                case NotifyManagement.UP_PROBE_EXIT_FAIL:// callback disconnectCB = 10 when bandwidth probe
                    // fail. Up_ui_gc.h
                    DebugLog.d(TAG,
                            "WebViewActivity.onStart() probe fail, GameActivity.m_player.bitrate_stopProbe()");
                    //mPlayer.bitrate_stopProbe();
                    notifyProbingCompleted(false);
                    /*if(bExitWaitProbeDone){
                       new Timer().schedule(new LogoutTimer(), 100);
                    }*/
                    break;
                case NotifyManagement.UP_GAME_NOTIFY_DISPLAYTEXT:
                    DebugLog.d(TAG, "notify UP_GAME_NOTIFY_DISPLAYTEXT");
                    gBNotifyDisplayExit = true;
                    gNotifyDisplayText = msgcontent;

                    break;
                case NotifyManagement.LOCAL_BROADCAST_CALL_UPDATE_STATE_200:
                    callJsUpdateStatus(Constants.RESPONSE_200);
                    break;

                case NotifyManagement.LOCAL_NOTIFY_WEBJS_GET_DUI:
                    String gid = bundle.getString("gid");
                    String useragent = bundle.getString("useragent");
                    DebugLog.d(TAG, "notify webview js get DUI gid=" + gid + ",useragent=" + useragent);
                    setToJsPlayMetadata(gid, useragent);
                    break;
                case NotifyManagement.LOCAL_GAMEACTIVITY_RESULT:
                    DebugLog.d(TAG, "Constants.LOCAL_GAMEACTIVITY_RESULT");
                    ((LoadWebJsActivity) mWebviewActivity).handleGameActivityResult();
                    break;

                case NotifyManagement.CAST_SESSION_STATUS_WEB:
                    DebugLog.d(TAG, "build session have done");

                    String deviceId;
                    String deviceName;
                    String status;

                    deviceId = bundle.getString("deviceId");
                    deviceName = bundle.getString("deviceName");
                    status = bundle.getString("status");
                    retPlayOnCast(deviceId, deviceName, status);

                    synchronized (mLock) {
                        mLock.notify();
                        DebugLog.d(TAG, "notify the thread");
                    }

                    break;
                }
            } else if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
                processNetworkType(intent, context);
            }

            if (intent.getAction().compareTo(Intent.ACTION_SCREEN_OFF) == 0) {
                DebugLog.d(TAG, "POWER ACTION_SCREEN_OFF");
                final LoadWebJsActivity loadWebJsActivity = (LoadWebJsActivity) mContext;
                loadWebJsActivity.gBEntryPowerKeyMode = true;
                loadWebJsActivity.gCurEntryBackgroundTime = System.currentTimeMillis();
            } else if (intent.getAction().compareTo(Intent.ACTION_SCREEN_ON) == 0) {
                DebugLog.d(TAG, "POWER ACTION_SCREEN_ON");
                final LoadWebJsActivity loadWebJsActivity = (LoadWebJsActivity) mContext;
                loadWebJsActivity.gBEntryPowerKeyMode = false;
                //   loadWebJsActivity.gCurEntryBackgroundTime = 0;

            }
        }
    };
    this.mContext.registerReceiver(boradcastListener, intentfilter);
}

From source file:com.moez.QKSMS.mmssms.Transaction.java

private void sendMMSWiFi(final byte[] bytesToSend) {
    // enable mms connection to mobile data
    mConnMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo.State state = mConnMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE_MMS).getState();

    if ((0 == state.compareTo(NetworkInfo.State.CONNECTED)
            || 0 == state.compareTo(NetworkInfo.State.CONNECTING))) {
        sendData(bytesToSend);/*from  w w w  . j  a v a2s .  c  o  m*/
    } else {
        int resultInt = mConnMgr.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE, "enableMMS");

        if (resultInt == 0) {
            try {
                Utils.ensureRouteToHost(context, settings.getMmsc(), settings.getProxy());
                sendData(bytesToSend);
            } catch (Exception e) {
                Log.e(TAG, "exception thrown", e);
                sendData(bytesToSend);
            }
        } else {
            // if mms feature is not already running (most likely isn't...) then register a receiver and wait for it to be active
            IntentFilter filter = new IntentFilter();
            filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
            final BroadcastReceiver receiver = new BroadcastReceiver() {

                @Override
                public void onReceive(Context context1, Intent intent) {
                    String action = intent.getAction();

                    if (!action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
                        return;
                    }

                    NetworkInfo mNetworkInfo = mConnMgr.getActiveNetworkInfo();
                    if ((mNetworkInfo == null)
                            || (mNetworkInfo.getType() != ConnectivityManager.TYPE_MOBILE_MMS)) {
                        return;
                    }

                    if (!mNetworkInfo.isConnected()) {
                        return;
                    } else {
                        alreadySending = true;

                        try {
                            Utils.ensureRouteToHost(context, settings.getMmsc(), settings.getProxy());
                            sendData(bytesToSend);
                        } catch (Exception e) {
                            Log.e(TAG, "exception thrown", e);
                            sendData(bytesToSend);
                        }

                        context.unregisterReceiver(this);
                    }

                }

            };

            context.registerReceiver(receiver, filter);

            try {
                Looper.prepare();
            } catch (Exception e) {
                // Already on UI thread probably
            }

            // try sending after 3 seconds anyways if for some reason the receiver doesn't work
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    if (!alreadySending) {
                        try {
                            context.unregisterReceiver(receiver);
                        } catch (Exception e) {

                        }

                        try {
                            Utils.ensureRouteToHost(context, settings.getMmsc(), settings.getProxy());
                            sendData(bytesToSend);
                        } catch (Exception e) {
                            Log.e(TAG, "exception thrown", e);
                            sendData(bytesToSend);
                        }
                    }
                }
            }, 7000);
        }
    }
}

From source file:com.irccloud.android.NetworkConnection.java

public void registerForConnectivity() {
    try {// w w  w.ja v  a  2  s .co  m
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
        IRCCloudApplication.getInstance().getApplicationContext().registerReceiver(connectivityListener,
                intentFilter);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.sipdroid.sipua.ui.Receiver.java

@Override
public void onReceive(Context context, Intent intent) {
    String intentAction = intent.getAction();
    if (!Sipdroid.on(context))
        return;/*  w ww  .j a  v a2  s . com*/
    if (!Sipdroid.release)
        Log.i("SipUA:", intentAction);
    if (mContext == null)
        mContext = context;
    if (intentAction.equals(Intent.ACTION_BOOT_COMPLETED)) {
        on_vpn(false);
        engine(context).register();
    } else if (intentAction.equals(ConnectivityManager.CONNECTIVITY_ACTION)
            || intentAction.equals(ACTION_EXTERNAL_APPLICATIONS_AVAILABLE)
            || intentAction.equals(ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE)
            || intentAction.equals(Intent.ACTION_PACKAGE_REPLACED)) {
        engine(context).register();
    } else if (intentAction.equals(ACTION_VPN_CONNECTIVITY) && intent.hasExtra("connection_state")) {
        String state = intent.getSerializableExtra("connection_state").toString();
        if (state != null && on_vpn() != state.equals("CONNECTED")) {
            on_vpn(state.equals("CONNECTED"));
            for (SipProvider sip_provider : engine(context).sip_providers)
                if (sip_provider != null)
                    sip_provider.haltConnections();
            engine(context).register();
        }
    } else if (intentAction.equals(ACTION_DATA_STATE_CHANGED)) {
        engine(context).registerMore();
    } else if (intentAction.equals(ACTION_PHONE_STATE_CHANGED)
            && !intent.getBooleanExtra(context.getString(R.string.app_name), false)) {
        stopRingtone();
        pstn_state = intent.getStringExtra("state");
        pstn_time = SystemClock.elapsedRealtime();
        if (pstn_state.equals("IDLE") && call_state != UserAgent.UA_STATE_IDLE)
            broadcastCallStateChanged(null, null);
        if (!pstn_state.equals("IDLE") && call_state == UserAgent.UA_STATE_INCALL)
            mHandler.sendEmptyMessageDelayed(MSG_HOLD, 5000);
        else if (!pstn_state.equals("IDLE") && (call_state == UserAgent.UA_STATE_INCOMING_CALL
                || call_state == UserAgent.UA_STATE_OUTGOING_CALL))
            mHandler.sendEmptyMessageDelayed(MSG_HANGUP, 5000);
        else if (pstn_state.equals("IDLE")) {
            mHandler.removeMessages(MSG_HOLD);
            mHandler.removeMessages(MSG_HANGUP);
            if (call_state == UserAgent.UA_STATE_HOLD)
                mHandler.sendEmptyMessageDelayed(MSG_HOLD, 1000);
        }
    } else if (intentAction.equals(ACTION_DOCK_EVENT)) {
        docked = intent.getIntExtra(EXTRA_DOCK_STATE, -1) & 7;
        if (call_state == UserAgent.UA_STATE_INCALL)
            engine(mContext).speaker(speakermode());
    } else if (intentAction.equals(ACTION_SCO_AUDIO_STATE_CHANGED)) {
        bluetooth = intent.getIntExtra(EXTRA_SCO_AUDIO_STATE, -1);
        progress();
        RtpStreamSender.changed = true;
    } else if (intentAction.equals(Intent.ACTION_HEADSET_PLUG)) {
        headset = intent.getIntExtra("state", -1);
        if (call_state == UserAgent.UA_STATE_INCALL)
            engine(mContext).speaker(speakermode());
    } else if (intentAction.equals(Intent.ACTION_SCREEN_ON)) {
        if (!PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean(
                org.sipdroid.sipua.ui.Settings.PREF_OWNWIFI, org.sipdroid.sipua.ui.Settings.DEFAULT_OWNWIFI))
            alarm(0, OwnWifi.class);
    } else if (intentAction.equals(Intent.ACTION_USER_PRESENT)) {
        mHandler.sendEmptyMessageDelayed(MSG_ENABLE, 3000);
    } else if (intentAction.equals(Intent.ACTION_SCREEN_OFF)) {
        if (PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean(
                org.sipdroid.sipua.ui.Settings.PREF_OWNWIFI, org.sipdroid.sipua.ui.Settings.DEFAULT_OWNWIFI)) {
            WifiManager wm = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
            WifiInfo wi = wm.getConnectionInfo();
            if (wm.getWifiState() != WifiManager.WIFI_STATE_ENABLED || wi == null
                    || wi.getSupplicantState() != SupplicantState.COMPLETED || wi.getIpAddress() == 0)
                alarm(2 * 60, OwnWifi.class);
            else
                alarm(15 * 60, OwnWifi.class);
        }
        if (SipdroidEngine.pwl != null)
            for (PowerManager.WakeLock pwl : SipdroidEngine.pwl)
                if (pwl != null && pwl.isHeld()) {
                    pwl.release();
                    pwl.acquire();
                }
    } else if (intentAction.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
        if (PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean(
                org.sipdroid.sipua.ui.Settings.PREF_SELECTWIFI,
                org.sipdroid.sipua.ui.Settings.DEFAULT_SELECTWIFI))
            mHandler.sendEmptyMessageDelayed(MSG_SCAN, 3000);
    } else if (intentAction.equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {
        if (SystemClock.uptimeMillis() > lastscan + 45000
                && PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean(
                        org.sipdroid.sipua.ui.Settings.PREF_SELECTWIFI,
                        org.sipdroid.sipua.ui.Settings.DEFAULT_SELECTWIFI)) {
            WifiManager wm = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
            WifiInfo wi = wm.getConnectionInfo();
            String activeSSID = null;
            if (wi != null)
                activeSSID = wi.getSSID();
            if (activeSSID != null && (activeSSID.length() == 0 || activeSSID.equals("0x")))
                activeSSID = null;
            List<ScanResult> mScanResults = wm.getScanResults();
            List<WifiConfiguration> configurations = wm.getConfiguredNetworks();
            if (configurations != null) {
                WifiConfiguration bestconfig = null, maxconfig = null, activeconfig = null;
                for (final WifiConfiguration config : configurations) {
                    if (maxconfig == null || config.priority > maxconfig.priority) {
                        maxconfig = config;
                    }
                    if (config.SSID != null
                            && (config.SSID.equals("\"" + activeSSID + "\"") || config.SSID.equals(activeSSID)))
                        activeconfig = config;
                }
                ScanResult bestscan = null, activescan = null;
                if (mScanResults != null)
                    for (final ScanResult scan : mScanResults) {
                        for (final WifiConfiguration config : configurations) {
                            if (config.SSID != null && config.SSID.equals("\"" + scan.SSID + "\"")) {
                                if (bestscan == null || scan.level > bestscan.level) {
                                    bestscan = scan;
                                    bestconfig = config;
                                }
                                if (config == activeconfig)
                                    activescan = scan;
                            }
                        }
                    }
                if (activescan != null)
                    System.out.println("debug wifi asu(active)" + asu(activescan));
                if (bestconfig != null && (activeconfig == null || bestconfig.priority != activeconfig.priority)
                        && asu(bestscan) > asu(activescan) * 1.5 &&
                        /* (activeSSID == null || activescan != null) && */ asu(bestscan) > 22) {
                    if (!Sipdroid.release)
                        Log.i("SipUA:", "changing to " + bestconfig.SSID);
                    if (activeSSID == null || !activeSSID.equals(bestscan.SSID))
                        wm.disconnect();
                    bestconfig.priority = maxconfig.priority + 1;
                    wm.updateNetwork(bestconfig);
                    wm.enableNetwork(bestconfig.networkId, true);
                    wm.saveConfiguration();
                    if (activeSSID == null || !activeSSID.equals(bestscan.SSID))
                        wm.reconnect();
                    lastscan = SystemClock.uptimeMillis();
                } else if (activescan != null && asu(activescan) < 15) {
                    wm.disconnect();
                    wm.disableNetwork(activeconfig.networkId);
                    wm.saveConfiguration();
                }
            }
        }
    }
}

From source file:org.tomahawk.tomahawk_android.activities.TomahawkMainActivity.java

@Override
public void onResume() {
    super.onResume();

    ACTIONBAR_HEIGHT = TomahawkApp.getContext().getResources()
            .getDimensionPixelSize(R.dimen.abc_action_bar_default_height_material);

    if (mSlidingUpPanelLayout.isPanelHidden()) {
        mPlaybackPanel.setVisibility(View.GONE);
    } else {//from ww w.j  a v  a2s  .c o m
        mPlaybackPanel.setup(mSlidingUpPanelLayout.isPanelExpanded());
        mPlaybackPanel.update(mPlaybackService);
        mPlaybackPanel.setVisibility(View.VISIBLE);
        if (mSlidingUpPanelLayout.isPanelExpanded()) {
            onPanelSlide(mSlidingUpPanelLayout, 1f);
        } else {
            onPanelSlide(mSlidingUpPanelLayout, 0f);
        }
    }

    if (mShouldShowAnimationHandler == null) {
        mShouldShowAnimationHandler = new Handler();
        mShouldShowAnimationHandler.post(mShouldShowAnimationRunnable);
    }

    if (mProgressHandler == null) {
        mProgressHandler = new ProgressHandler(this);
        if (mPlaybackService != null && mPlaybackService.getCurrentTrack() != null
                && mPlaybackService.isPlaying()) {
            mProgressHandler.sendEmptyMessage(0);
        }
    }

    if (mTomahawkMainReceiver == null) {
        mTomahawkMainReceiver = new TomahawkMainReceiver();
    }

    // Register intents that the BroadcastReceiver should listen to
    registerReceiver(mTomahawkMainReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
}

From source file:com.csipsimple.service.SipService.java

/**
 * Register broadcast receivers./*from w  ww. ja v a2s .c om*/
 */
private void registerBroadcasts() {
    // Register own broadcast receiver
    if (deviceStateReceiver == null) {
        IntentFilter intentfilter = new IntentFilter();
        intentfilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
        intentfilter.addAction(SipManager.ACTION_SIP_ACCOUNT_CHANGED);
        intentfilter.addAction(SipManager.ACTION_SIP_ACCOUNT_DELETED);
        intentfilter.addAction(SipManager.ACTION_SIP_CAN_BE_STOPPED);
        intentfilter.addAction(SipManager.ACTION_SIP_REQUEST_RESTART);
        intentfilter.addAction(DynamicReceiver4.ACTION_VPN_CONNECTIVITY);
        if (Compatibility.isCompatible(5)) {
            deviceStateReceiver = new DynamicReceiver5(this);
        } else {
            deviceStateReceiver = new DynamicReceiver4(this);
        }
        registerReceiver(deviceStateReceiver, intentfilter);
        deviceStateReceiver.startMonitoring();
    }
    // Telephony
    if (phoneConnectivityReceiver == null) {
        Log.d(THIS_FILE, "Listen for phone state ");
        phoneConnectivityReceiver = new ServicePhoneStateReceiver();

        telephonyManager.listen(phoneConnectivityReceiver, /*PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
                                                           | */PhoneStateListener.LISTEN_CALL_STATE);
    }
    // Content observer
    if (statusObserver == null) {
        statusObserver = new AccountStatusContentObserver(serviceHandler);
        getContentResolver().registerContentObserver(SipProfile.ACCOUNT_STATUS_URI, true, statusObserver);
    }

}

From source file:com.nbplus.iotapp.service.IoTService.java

@Override
public void onCreate() {
    Log.i(TAG, "debug: Creating service");
    sendBroadcast(new Intent(IoTConstants.ACTION_SERVICE_CREATE_BROADCAST));
    /**/*from  w w  w. ja va 2s  . c o  m*/
     * Target we publish for clients to send messages to IncomingHandler.Note
     * that calls to its binder are sequential!
     */
    mServiceMessenger = new Messenger(mHandler);

    mUseIoTGateway = IoTServicePreference.isUseIoTGateway(this);
    if (mUseIoTGateway) {
        Log.d(TAG, ">> Use IoT Gateway....");
        // Create the Wifi lock (this does not acquire the lock, this just creates it)
        mWifiLock = ((WifiManager) getSystemService(Context.WIFI_SERVICE))
                .createWifiLock(WifiManager.WIFI_MODE_FULL, IoTService.class.getSimpleName() + "_lock");

        // check network status
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
        registerReceiver(mBroadcastReceiver, intentFilter);

        mLastConnectionStatus = NetworkUtils.isConnected(this);

        // TODO : connect to iot gateway
        if (mThreadPooledServer != null) {
            mThreadPooledServer.stop(false);
        }
        mThreadPooledServer = new ThreadPooledServer(mServiceMessenger, IoTConstants.IOT_GATEWAY_SERVER_PORT,
                IoTConstants.IOT_GATEWAY_SERVER_THREAD_POOL_SIZE);
        new Thread(mThreadPooledServer).start();
    } else {
        Log.d(TAG, ">> Use internal blutooth....");
        // check bluetooth status
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
        registerReceiver(mBroadcastReceiver, intentFilter);

        // bluetooth local broadcast
        intentFilter = makeGattUpdateIntentFilter();
        LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver, intentFilter);

        // connect to ble service
        mErrorCodes = checkBluetoothEnabled();
        if (mErrorCodes.equals(IoTResultCodes.SUCCESS)) {
            try {
                if (mBluetoothServiceConnection != null) {
                    unbindService(mBluetoothServiceConnection);
                }
            } catch (Exception e) {

            }
            final Intent gattServiceIntent = new Intent(this, BluetoothLeService.class);
            bindService(gattServiceIntent, mBluetoothServiceConnection, BIND_AUTO_CREATE);
        } else {
            mServiceStatus = IoTServiceStatus.STOPPED;
            Log.d(TAG, "Internal bluetooth error = " + mErrorCodes);
        }
    }
}

From source file:com.tct.mail.ui.ConversationListFragment.java

@Override
public void onResume() {
    super.onResume();

    if (!isCursorReadyToShow()) {
        // If the cursor got reset, let's reset the analytics state variable and show the list
        // view since we are waiting for load again
        mInitialCursorLoading = true;/*from   w ww.j  a  va2  s  .c o  m*/
        showListView();
    }

    final ConversationCursor conversationCursor = getConversationListCursor();
    if (conversationCursor != null) {
        conversationCursor.handleNotificationActions();

        restoreLastScrolledPosition();
    }

    mSelectedSet.addObserver(mConversationSetObserver);
    //TS: wenggangjin 2015-01-26 EMAIL BUGFIX_-908180 MOD_S
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);
    filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);//TS: junwei-xu 2015-1-26 EMAIL BUGFIX_898211 ADD
    getActivity().registerReceiver(myReceiver, filter);
    //TS: wenggangjin 2015-01-26 EMAIL BUGFIX_-908180 MOD_E
}