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:RhodesService.java

@Override
public void onCreate() {
    Logger.D(TAG, "onCreate");

    sInstance = this;

    Context context = this;

    mNM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    LocalFileProvider.revokeUriPermissions(this);

    Logger.I("Rhodes", "Loading...");
    RhodesApplication.create();/*from w  w  w. j  a  va2s.  c  o m*/

    RhodesActivity ra = RhodesActivity.getInstance();
    if (ra != null) {
        // Show splash screen only if we have active activity
        SplashScreen splashScreen = ra.getSplashScreen();
        splashScreen.start();

        // Increase WebView rendering priority
        WebView w = new WebView(context);
        WebSettings webSettings = w.getSettings();
        webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
    }

    initForegroundServiceApi();

    // Register custom uri handlers here
    mUriHandlers.addElement(new ExternalHttpHandler(context));
    mUriHandlers.addElement(new LocalFileHandler(context));
    mUriHandlers.addElement(new MailUriHandler(context));
    mUriHandlers.addElement(new TelUriHandler(context));
    mUriHandlers.addElement(new SmsUriHandler(context));
    mUriHandlers.addElement(new VideoUriHandler(context));

    mConnectionChangeReceiver = new ConnectionChangeReceiver();
    IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(mConnectionChangeReceiver, filter);

    RhodesApplication.start();

    if (BaseActivity.getActivitiesCount() > 0)
        handleAppActivation();
}

From source file:org.ulteo.ovd.MainWindow.java

@Override
protected synchronized void onResume() {
    // restart internet connection status watching thread
    IntentFilter filter = new IntentFilter();
    filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(statusRun, filter);
    Boolean net = checkConnectivity();
    startBtn.setEnabled(net);//from w  w w .ja va2  s  . c  o  m
    tvNoNet.setVisibility(net ? View.GONE : View.VISIBLE);
    findViewById(R.id.sessionm_layout).setVisibility(Settings.getHideSm(this) ? View.GONE : View.VISIBLE);
    // reload user preferences
    LoadSelections();

    // Always show the session if one is opened.
    if (AndRdpActivity.getRdp() != null)
        startActivityForResult(new Intent(MainWindow.this, AndRdpActivity.class), 1);

    super.onResume();
}

From source file:org.pixmob.freemobile.netstat.MonitorService.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override/*from w w w .  jav a 2 s .  c  o m*/
public void onCreate() {
    super.onCreate();

    pm = (PowerManager) getSystemService(POWER_SERVICE);
    tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);

    prefs = getSharedPreferences(SP_NAME, MODE_PRIVATE);
    prefs.registerOnSharedPreferenceChangeListener(this);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        final int largeIconWidth = getResources()
                .getDimensionPixelSize(android.R.dimen.notification_large_icon_width);
        final int largeIconHeight = getResources()
                .getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
        if ((largeIconWidth > 0) && (largeIconHeight > 0)) {
            Bitmap freeLargeIconTmp = BitmapFactory.decodeResource(getResources(),
                    R.drawable.ic_stat_notify_service_free_large);
            if ((freeLargeIconTmp != null) && (freeLargeIconTmp.getWidth() > 0)
                    && (freeLargeIconTmp.getHeight() > 0)) {
                freeLargeIcon = Bitmap.createScaledBitmap(freeLargeIconTmp, largeIconWidth, largeIconHeight,
                        true);
            }

            Bitmap freeFemtoLargeIconTmp = BitmapFactory.decodeResource(getResources(),
                    R.drawable.ic_stat_notify_service_free_femto_large);
            if ((freeFemtoLargeIconTmp != null) && (freeFemtoLargeIconTmp.getHeight() > 0)
                    && (freeFemtoLargeIconTmp.getWidth() > 0)) {
                freeFemtoLargeIcon = Bitmap.createScaledBitmap(freeFemtoLargeIconTmp, largeIconWidth,
                        largeIconHeight, true);
            }

            Bitmap orangeLargeIconTmp = BitmapFactory.decodeResource(getResources(),
                    R.drawable.ic_stat_notify_service_orange_large);
            if ((orangeLargeIconTmp != null) && (orangeLargeIconTmp.getHeight() > 0)
                    && (orangeLargeIconTmp.getWidth() > 0)) {
                orangeLargeIcon = Bitmap.createScaledBitmap(orangeLargeIconTmp, largeIconWidth, largeIconHeight,
                        true);
            }
        }
    }

    // Initialize and start a worker thread for inserting rows into the
    // application database.
    final Context c = getApplicationContext();
    pendingInsert = new ArrayBlockingQueue<>(8);
    new PendingInsertWorker(c, pendingInsert).start();

    // This intent is fired when the application notification is clicked.
    openUIPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_NOTIFICATION),
            PendingIntent.FLAG_CANCEL_CURRENT);

    // This intent is only available as a Jelly Bean notification action in
    // order to open network operator settings.
    Intent networkSettingsIntent = IntentFactory.networkOperatorSettings(this);
    if (networkSettingsIntent != null) {
        networkOperatorSettingsPendingIntent = PendingIntent.getActivity(this, 0, networkSettingsIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);
    }
    Intent wirelessSettingsIntent = IntentFactory.wirelessSettings(this);
    if (wirelessSettingsIntent != null) {
        wirelessSettingsPendingIntent = PendingIntent.getActivity(this, 0, wirelessSettingsIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);
    }

    // Watch screen light: is the screen on?
    screenMonitor = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            updateEventDatabase();
        }
    };

    final IntentFilter screenIntentFilter = new IntentFilter();
    screenIntentFilter.addAction(Intent.ACTION_SCREEN_ON);
    screenIntentFilter.addAction(Intent.ACTION_SCREEN_OFF);
    registerReceiver(screenMonitor, screenIntentFilter);

    // Watch Wi-Fi connections.
    connectionMonitor = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (onConnectivityUpdated()) {
                updateEventDatabase();
            }
        }
    };

    final IntentFilter connectionIntentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(connectionMonitor, connectionIntentFilter);

    // Watch mobile connections.
    phoneMonitor = new PhoneStateListener() {
        @Override
        public void onDataConnectionStateChanged(int state, int networkType) {
            updateService();
        }

        @Override
        public void onServiceStateChanged(ServiceState serviceState) {
            if (stopServiceIfSimOperatorIsNotFreeMobile())
                return;

            mobileNetworkConnected = (serviceState != null)
                    && (serviceState.getState() == ServiceState.STATE_IN_SERVICE);

            updateService();
        }

        @Override
        public void onCellInfoChanged(List<CellInfo> cellInfo) {
            updateService();
        }

        private void updateService() {
            if (tm != null) { // Fix NPE - found by Acralyzer
                mobileNetworkType = tm.getNetworkType(); //update the network type to have the latest
            }
            final int phoneStateUpdated = onPhoneStateUpdated();
            if (phoneStateUpdated >= 0)
                updateEventDatabase();

            updateNotification(true, phoneStateUpdated == 1);
        }
    };
    int events = PhoneStateListener.LISTEN_SERVICE_STATE | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
        events |= PhoneStateListener.LISTEN_CELL_INFO;

    tm.listen(phoneMonitor, events);

    // Watch battery level.
    batteryMonitor = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            updateEventDatabase();
        }
    };

    batteryIntentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    registerReceiver(batteryMonitor, batteryIntentFilter);

    shutdownMonitor = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            onDeviceShutdown();
        }
    };
    final IntentFilter shutdownIntentFilter = new IntentFilter();
    shutdownIntentFilter.addAction(Intent.ACTION_SHUTDOWN);
    // HTC devices use a different Intent action:
    // http://stackoverflow.com/q/5076410/422906
    shutdownIntentFilter.addAction("android.intent.action.QUICKBOOT_POWEROFF");
    registerReceiver(shutdownMonitor, shutdownIntentFilter);

    if (prefs.getBoolean(SP_KEY_ENABLE_AUTO_RESTART_SERVICE, false) && Arrays
            .asList(ANDROID_VERSIONS_ALLOWED_TO_AUTO_RESTART_SERVICE).contains(Build.VERSION.RELEASE)) {
        // Kitkat and JellyBean auto-kill service workaround
        // http://stackoverflow.com/a/20735519/1527491
        ensureServiceStaysRunning();
    }
}

From source file:ee.ria.DigiDoc.fragment.ContainerDetailsFragment.java

private void registerBroadcastReceivers() {
    getActivity().registerReceiver(cardInsertedReceiver, new IntentFilter(ACS.CARD_PRESENT_INTENT));
    getActivity().registerReceiver(cardRemovedReceiver, new IntentFilter(ACS.CARD_ABSENT_INTENT));
    getActivity().registerReceiver(connectivityBroadcastReceiver,
            new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mobileIdBroadcastReceiver,
            new IntentFilter(MID_BROADCAST_ACTION));
}

From source file:org.universAAL.android.services.MiddlewareService.java

@Override
public int onStartCommand(final Intent intent, int flags, int startId) {
    // This will be called each time someone (scan/boot/wifi) sends an intent to this service. Analyze and react accordingly.
    Log.v(TAG, "Start command: ");
    // HACK: Set user type for AndroidHandler. Prevents NPE at startup when activity is not visible
    mUserType = Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(MiddlewareService.this)
            .getString("setting_type_key", Integer.toString(AppConstants.Defaults.TYPE)));
    new Thread(new Runnable() {
        public void run() {
            if (intent != null) {
                String action = intent.getAction();
                Log.v(TAG, "Intent action: " + action);
                if (action != null) {
                    if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
                        //Do nothing, the MW is already started by now in oncreate
                        Log.v(TAG, "Action is BOOT");
                    } else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)
                            || action.equals("android.net.wifi.STATE_CHANGE")) {
                        // Only react to meaningful changes
                        Log.v(TAG, "Action is WIFI");
                        int newWifi = checkWifi(); //Dont set mCurrentWifi yet, we have to compare
                        if (Config.isWifiAllowed()) {
                            boolean modeGW = (Config.getRemoteMode() == AppConstants.REMOTE_MODE_WIFIOFF);
                            switch (newWifi) {
                            case AppConstants.WIFI_OFF:
                                if (mCurrentWIFI == AppConstants.WIFI_NOTSET
                                        || mCurrentWIFI == AppConstants.WIFI_HOME) {
                                    if (modeGW) {
                                        stopGateway();
                                    }//from  w w  w .java2s .co m
                                    restartConnector(false); // Shut down jSLP, use GW
                                    if (modeGW) {
                                        startGateway();
                                    }
                                }
                                break;
                            case AppConstants.WIFI_NOTSET:
                                if (mCurrentWIFI == AppConstants.WIFI_OFF
                                        || mCurrentWIFI == AppConstants.WIFI_STRANGER) {
                                    if (modeGW) {
                                        stopGateway();
                                    }
                                    restartConnector(true); // Turn on jSLP, dont use GW
                                }
                                break;
                            case AppConstants.WIFI_STRANGER:
                                if (mCurrentWIFI == AppConstants.WIFI_NOTSET
                                        || mCurrentWIFI == AppConstants.WIFI_HOME) {
                                    if (modeGW) {
                                        stopGateway();
                                    }
                                    restartConnector(false); // Shut down jSLP, use GW
                                    if (modeGW) {
                                        startGateway();
                                    }
                                }
                                break;
                            case AppConstants.WIFI_HOME:
                                if (mCurrentWIFI == AppConstants.WIFI_OFF
                                        || mCurrentWIFI == AppConstants.WIFI_STRANGER) {
                                    if (modeGW) {
                                        stopGateway();
                                    }
                                    restartConnector(true); // Turn on jSLP, dont use GW
                                }
                                break;
                            default:
                                // Do nothing, keep using jSLP / GW or not, as previous state
                                break;
                            }
                        }
                        mCurrentWIFI = newWifi;
                    } else if (action.equals(AppConstants.ACTION_PCK_REG)) {
                        // REGISTER message from scan service
                        Log.v(TAG, "Action is REGISTER");
                        AndroidRegistry.register(intent.getStringExtra(AppConstants.ACTION_PCK_REG_X_ID),
                                (GroundingParcel) intent
                                        .getParcelableExtra(AppConstants.ACTION_PCK_REG_X_PARCEL),
                                intent.getIntExtra(AppConstants.ACTION_PCK_REG_X_TYPE, 0),
                                MiddlewareService.this);
                    } else if (action.equals(AppConstants.ACTION_PCK_UNREG)) {
                        // UNREGISTER message from scan service
                        Log.v(TAG, "Action is UNREGISTER");
                        AndroidRegistry.unregister(intent.getStringExtra(AppConstants.ACTION_PCK_UNREG_X_ID),
                                intent.getIntExtra(AppConstants.ACTION_PCK_UNREG_X_TYPE, 0));
                    } else {
                        // Not the right action yet (TODO check if from receivers)
                        Log.v(TAG, "Action is... Not the right action yet");
                    }
                } else {
                    // If (action=null) who?
                    Log.v(TAG, "Action is none");
                }
            }
        }
    }, TAG_THREAD_START).start();
    return START_STICKY;
}

From source file:com.ferdi2005.secondgram.voip.VoIPService.java

@Override
public void onCreate() {
    super.onCreate();
    FileLog.d("=============== VoIPService STARTING ===============");
    AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1
            && am.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER) != null) {
        int outFramesPerBuffer = Integer
                .parseInt(am.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER));
        VoIPController.setNativeBufferSize(outFramesPerBuffer);
    } else {//  w ww .ja  va2s . co  m
        VoIPController.setNativeBufferSize(
                AudioTrack.getMinBufferSize(48000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT)
                        / 2);
    }
    final SharedPreferences preferences = getSharedPreferences("mainconfig", MODE_PRIVATE);
    VoIPServerConfig.setConfig(preferences.getString("voip_server_config", "{}"));
    if (System.currentTimeMillis() - preferences.getLong("voip_server_config_updated", 0) > 24 * 3600000) {
        ConnectionsManager.getInstance().sendRequest(new TLRPC.TL_phone_getCallConfig(), new RequestDelegate() {
            @Override
            public void run(TLObject response, TLRPC.TL_error error) {
                if (error == null) {
                    String data = ((TLRPC.TL_dataJSON) response).data;
                    VoIPServerConfig.setConfig(data);
                    preferences.edit().putString("voip_server_config", data)
                            .putLong("voip_server_config_updated",
                                    BuildConfig.DEBUG ? 0 : System.currentTimeMillis())
                            .apply();
                }
            }
        });
    }
    try {
        controller = new VoIPController();
        controller.setConnectionStateListener(this);
        controller.setConfig(MessagesController.getInstance().callPacketTimeout / 1000.0,
                MessagesController.getInstance().callConnectTimeout / 1000.0,
                preferences.getInt("VoipDataSaving", VoIPController.DATA_SAVING_NEVER));

        cpuWakelock = ((PowerManager) getSystemService(POWER_SERVICE))
                .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "telegram-voip");
        cpuWakelock.acquire();

        btAdapter = am.isBluetoothScoAvailableOffCall() ? BluetoothAdapter.getDefaultAdapter() : null;

        IntentFilter filter = new IntentFilter();
        filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
        filter.addAction(ACTION_HEADSET_PLUG);
        if (btAdapter != null) {
            filter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
            filter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED);
        }
        filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
        filter.addAction(getPackageName() + ".END_CALL");
        filter.addAction(getPackageName() + ".DECLINE_CALL");
        filter.addAction(getPackageName() + ".ANSWER_CALL");
        registerReceiver(receiver, filter);

        ConnectionsManager.getInstance().setAppPaused(false, false);

        soundPool = new SoundPool(1, AudioManager.STREAM_VOICE_CALL, 0);
        spConnectingId = soundPool.load(this, R.raw.voip_connecting, 1);
        spRingbackID = soundPool.load(this, R.raw.voip_ringback, 1);
        spFailedID = soundPool.load(this, R.raw.voip_failed, 1);
        spEndId = soundPool.load(this, R.raw.voip_end, 1);
        spBusyId = soundPool.load(this, R.raw.voip_busy, 1);

        am.registerMediaButtonEventReceiver(new ComponentName(this, VoIPMediaButtonReceiver.class));

        if (btAdapter != null && btAdapter.isEnabled()) {
            int headsetState = btAdapter.getProfileConnectionState(BluetoothProfile.HEADSET);
            updateBluetoothHeadsetState(headsetState == BluetoothProfile.STATE_CONNECTED);
            if (headsetState == BluetoothProfile.STATE_CONNECTED)
                am.setBluetoothScoOn(true);
            for (StateListener l : stateListeners)
                l.onAudioSettingsChanged();
        }

        NotificationCenter.getInstance().addObserver(this, NotificationCenter.appDidLogout);
    } catch (Exception x) {
        FileLog.e("error initializing voip controller", x);
        callFailed();
    }
}

From source file:at.alladin.rmbt.android.main.RMBTMainActivity.java

/**
* 
*//* w w w. j a va2s . co  m*/
@Override
public void onCreate(final Bundle savedInstanceState) {
    //Log.i("MAIN ACTIVITY", "onCreate");
    restoreInstance(savedInstanceState);
    super.onCreate(savedInstanceState);
    NetworkInfoCollector.init(this);
    networkInfoCollector = NetworkInfoCollector.getInstance();

    preferencesUpdate();
    setContentView(R.layout.main_with_navigation_drawer);

    if (VIEW_HIERARCHY_SERVER_ENABLED) {
        ViewServer.get(this).addWindow(this);
    }

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
    actionBar.setDisplayUseLogoEnabled(true);

    // initialize the navigation drawer with the main menu list adapter:
    String[] mainTitles = getResources().getStringArray(R.array.navigation_main_titles);
    int[] navIcons = new int[] { R.drawable.ic_action_home, R.drawable.ic_action_history,
            R.drawable.ic_action_map, R.drawable.ic_action_stat, R.drawable.ic_action_help,
            R.drawable.ic_action_about, R.drawable.ic_action_settings, R.drawable.ic_action_about };

    MainMenuListAdapter mainMenuAdapter = new MainMenuListAdapter(this, mainTitles, navIcons);

    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawerList = (ListView) findViewById(R.id.left_drawer);
    drawerLayout.setBackgroundResource(R.drawable.ic_drawer);

    drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer,
            R.string.page_title_title_page, R.string.page_title_title_page) {

        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            //refreshActionBar(null);
            exitAfterDrawerClose = false;
        }

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
        }
    };

    drawerLayout.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (KeyEvent.KEYCODE_BACK == event.getKeyCode() && exitAfterDrawerClose) {
                onBackPressed();
                return true;
            }
            return false;
        }
    });
    drawerLayout.setDrawerListener(drawerToggle);
    drawerList.setAdapter(mainMenuAdapter);
    drawerList.setOnItemClickListener(new OnItemClickListener() {
        final int[] menuIds = new int[] { R.id.action_title_page, R.id.action_history, R.id.action_map,
                R.id.action_stats, R.id.action_help, R.id.action_info, R.id.action_settings,
                R.id.action_netstat, R.id.action_log };

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectMenuItem(menuIds[position]);
            drawerLayout.closeDrawers();
        }
    });

    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);

    // Do something against banding effect in gradients
    // Dither flag might mess up on certain devices??
    final Window window = getWindow();
    window.setFormat(PixelFormat.RGBA_8888);
    window.addFlags(WindowManager.LayoutParams.FLAG_DITHER);

    // Setzt Default-Werte, wenn noch keine Werte vorhanden
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

    final String uuid = ConfigHelper.getUUID(getApplicationContext());

    fm = getFragmentManager();
    final Fragment fragment = fm.findFragmentById(R.id.fragment_content);
    if (!ConfigHelper.isTCAccepted(this)) {
        if (fragment != null && fm.getBackStackEntryCount() >= 1)
            // clear fragment back stack
            fm.popBackStack(fm.getBackStackEntryAt(0).getId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);

        getActionBar().hide();
        setLockNavigationDrawer(true);

        showTermsCheck();
    } else {
        currentMapOptions.put("highlight", uuid);
        if (fragment == null) {
            if (false) // deactivated for si // ! ConfigHelper.isNDTDecisionMade(this))
            {
                showTermsCheck();
                showNdtCheck();
            } else
                initApp(true);
        }
    }

    geoLocation = new MainGeoLocation(getApplicationContext());

    mNetworkStateChangedFilter = new IntentFilter();
    mNetworkStateChangedFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);

    mNetworkStateIntentReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(final Context context, final Intent intent) {
            if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
                final boolean connected = !intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY,
                        false);
                final boolean isFailover = intent.getBooleanExtra(ConnectivityManager.EXTRA_IS_FAILOVER, false);

                if (connected) {
                    if (networkInfoCollector != null) {
                        networkInfoCollector.setHasConnectionFromAndroidApi(true);
                    }
                } else {
                    if (networkInfoCollector != null) {
                        networkInfoCollector.setHasConnectionFromAndroidApi(false);
                    }
                }

                Log.i(DEBUG_TAG, "CONNECTED: " + connected + " FAILOVER: " + isFailover);
            }
        }
    };
}

From source file:com.bayapps.android.robophish.ui.MediaBrowserFragment.java

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

    // fetch browsing information to fill the listview:
    MediaBrowserCompat mediaBrowser = mMediaFragmentListener.getMediaBrowser();

    LogHelper.d(TAG, "fragment.onStart, mediaId=", mMediaId, "  onConnected=" + mediaBrowser.isConnected());

    if (mediaBrowser.isConnected()) {
        onConnected();/*w w  w. j  a v  a2  s .  c om*/
    }

    // Registers BroadcastReceiver to track network connection changes.
    this.getActivity().registerReceiver(mConnectivityChangeReceiver,
            new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
}

From source file:org.cm.podd.report.activity.HomeActivity.java

private void registerConnectivityChanged() {
    networkStateBroadcastReceiver = new BroadcastReceiver() {
        @Override//from   ww  w . ja v  a2 s .  c  o m
        public void onReceive(Context context, Intent intent) {
            Intent submitIntent = new Intent(context, DataSubmitService.class);
            DataSubmitService.enqueueWork(context, submitIntent);
        }
    };
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(networkStateBroadcastReceiver, intentFilter);
}

From source file:com.jins_meme.bridge.MainActivity.java

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

    IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(mNetworkStateReceiver, filter);

    isForeground = true;/*  w ww  . j  a  va 2s  .  c o m*/

    //if (Build.VERSION.SDK_INT >= 23) {
    //  requestGPSPermission();
    //}

    Log.d("DEBUG", "onResume..." + scannedMemeList.size());
}