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:im.neon.activity.LoginActivity.java

/**
 * Add a listener to be notified when the device gets connected to a network.
 * This method is mainly used to refresh the login UI upon the network is back.
 * See {@link #removeNetworkStateNotificationListener()}
 *//*from w  w w  .  j a  va2  s  .c  om*/
private void addNetworkStateNotificationListener() {
    if (null != Matrix.getInstance(getApplicationContext()) && !mIsWaitingNetworkConnection) {
        try {
            registerReceiver(mNetworkReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
            mIsWaitingNetworkConnection = true;
        } catch (Exception e) {
            Log.e(LOG_TAG, "## addNetworkStateNotificationListener : " + e.getMessage());
        }
    }
}

From source file:com.hamradiocoin.wallet.service.BlockchainServiceImpl.java

@Override
public void onCreate() {
    serviceCreatedAt = System.currentTimeMillis();
    log.debug(".onCreate()");

    super.onCreate();

    nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    final String lockName = getPackageName() + " blockchain sync";

    final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName);

    application = (WalletApplication) getApplication();
    config = application.getConfiguration();
    final Wallet wallet = application.getWallet();

    bestChainHeightEver = config.getBestChainHeightEver();

    peerConnectivityListener = new PeerConnectivityListener();

    sendBroadcastPeerState(0);//from   w ww .  j  a v  a2 s.c  om

    final IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW);
    intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK);
    registerReceiver(connectivityReceiver, intentFilter);

    blockChainFile = new File(getDir("blockstore", Context.MODE_PRIVATE), Constants.Files.BLOCKCHAIN_FILENAME);
    final boolean blockChainFileExists = blockChainFile.exists();

    if (!blockChainFileExists) {
        log.info("blockchain does not exist, resetting wallet");

        wallet.clearTransactions(0);
        wallet.setLastBlockSeenHeight(-1); // magic value
        wallet.setLastBlockSeenHash(null);
    }

    try {
        blockStore = new SPVBlockStore(Constants.NETWORK_PARAMETERS, blockChainFile);
        blockStore.getChainHead(); // detect corruptions as early as possible

        final long earliestKeyCreationTime = wallet.getEarliestKeyCreationTime();

        if (!blockChainFileExists && earliestKeyCreationTime > 0) {
            try {
                final InputStream checkpointsInputStream = getAssets()
                        .open(Constants.Files.CHECKPOINTS_FILENAME);
                CheckpointManager.checkpoint(Constants.NETWORK_PARAMETERS, checkpointsInputStream, blockStore,
                        earliestKeyCreationTime);
            } catch (final IOException x) {
                log.error("problem reading checkpoints, continuing without", x);
            }
        }
    } catch (final BlockStoreException x) {
        blockChainFile.delete();

        final String msg = "blockstore cannot be created";
        log.error(msg, x);
        throw new Error(msg, x);
    }

    log.info("using " + blockStore.getClass().getName());

    try {
        blockChain = new BlockChain(Constants.NETWORK_PARAMETERS, wallet, blockStore);
    } catch (final BlockStoreException x) {
        throw new Error("blockchain cannot be created", x);
    }

    application.getWallet().addEventListener(walletEventListener, Threading.SAME_THREAD);

    registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK));

    maybeRotateKeys();
}

From source file:com.shinymayhem.radiopresets.ServiceRadioPlayer.java

private void registerNetworkReceiver() {
    //register network receiver
    IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
    if (mReceiver != null) {
        if (LOCAL_LOGD)
            log("Metwork receiver already registered", "d"); //why? 
        this.unregisterReceiver(mReceiver);
        mReceiver = null;/*from  w  ww . j a  v a2s.c  o  m*/
    }
    mReceiver = new ReceiverNetwork();
    if (LOCAL_LOGV)
        log("registering network change broadcast receiver", "v");
    this.registerReceiver(mReceiver, filter);
}

From source file:cc.mintcoin.wallet.service.BlockchainServiceImpl.java

private void startBlockChain() {
    if (blockChain != null)
        return;/*  w w w.  j  a v a  2  s .  c  om*/

    final Wallet wallet = application.getWallet();

    final String lockName = getPackageName() + " blockchain sync";

    final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName);

    peerConnectivityListener = new PeerConnectivityListener();
    sendBroadcastPeerState(0);

    final IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW);
    intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK);
    registerReceiver(connectivityReceiver, intentFilter);

    boolean blockChainFileExists = blockChainFile.exists();

    if (!blockChainFileExists) {
        log.info("blockchain does not exist, resetting wallet");

        wallet.clearTransactions(0);
        wallet.setLastBlockSeenHeight(-1); // magic value
        wallet.setLastBlockSeenHash(null);
    }

    try {
        blockStore = new TxTrackingBlockStore(Constants.NETWORK_PARAMETERS, blockChainFile);
        blockStore.getChainHead(); // detect corruptions as early as possible

        final long earliestKeyCreationTime = wallet.getEarliestKeyCreationTime();
    } catch (final BlockStoreException x) {
        deleteBlockChainFile();

        final String msg = "blockstore cannot be created";
        log.error(msg, x);
        throw new Error(msg, x);
    }

    log.info("using " + blockStore.getClass().getName());

    try {
        blockChain = new TxTrackingBlockChain(Constants.NETWORK_PARAMETERS, wallet, blockStore);
    } catch (final BlockStoreException x) {
        throw new Error("blockchain cannot be created", x);
    }

    application.getWallet().addEventListener(walletEventListener, Threading.SAME_THREAD);

    registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK));

    maybeRotateKeys();
    return;
}

From source file:com.ebridgevas.android.ebridgeapp.messaging.mqttservice.MqttService.java

@SuppressWarnings("deprecation")
private void registerBroadcastReceivers() {
    if (networkConnectionMonitor == null) {
        networkConnectionMonitor = new NetworkConnectionIntentReceiver();
        registerReceiver(networkConnectionMonitor, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
    }/*from  w  ww.j  a  v  a  2s  . c o m*/

    if (Build.VERSION.SDK_INT < 14 /**Build.VERSION_CODES.ICE_CREAM_SANDWICH**/
    ) {
        // Support the old system for background data preferences
        ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
        backgroundDataEnabled = cm.getBackgroundDataSetting();
        if (backgroundDataPreferenceMonitor == null) {
            backgroundDataPreferenceMonitor = new BackgroundDataPreferenceReceiver();
            registerReceiver(backgroundDataPreferenceMonitor,
                    new IntentFilter(ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED));
        }
    }
}

From source file:com.septrivium.augeo.ui.SipHome.java

@Override
protected void onResume() {
    Log.d(THIS_FILE, "On Resume SIPHOME");
    super.onResume();
    onForeground = true;//  ww w .j a  v  a 2  s .  c om
    registerReceiver(connectionReciever, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));

    assignDialPadFromDeviceProfilePrefs();

    prefProviderWrapper.setPreferenceBooleanValue(PreferencesWrapper.HAS_BEEN_QUIT, false);

    // Set visible the currently selected account
    sendFragmentVisibilityChange(mViewPager.getCurrentItem(), true);

    Log.d(THIS_FILE, "WE CAN NOW start SIP service");
    startSipService();
    applyTheme();
}

From source file:co.beem.project.beem.FbTextService.java

/**
 * {@inheritDoc}/*  ww  w . j a v a 2 s .c  om*/
 */
@Override
public void onCreate() {
    super.onCreate();
    Utils.setContext(getApplicationContext());
    smackAndroid = SmackAndroid.init(FbTextService.this);
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    savingMessageQueue = new LinkedBlockingQueue<co.beem.project.beem.service.BeemMessage>();
    stateChangeQueue = new LinkedBlockingQueue<User>();
    sendImageQueue = new LinkedBlockingDeque<ImageMessageInQueue>();
    isRunning = true;
    sessionManager = new SessionManager(FbTextService.this);
    savingMessageOnBackgroundThread(new SavingNewMessageTask());
    savingMessageOnBackgroundThread(new UpdateUserStateTask());
    savingMessageOnBackgroundThread(new SendImageTask());
    handler = new Handler();
    registerReceiver(mReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
    this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
    this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CONNECTED));
    this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CONNECTING));
    this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_DISCONNECT));
    this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CONNECTING_In));
    registerReceiver(mOnOffReceiver, new IntentFilter(FbTextApplication.SEND_IMAGE_MESSAGE));
    registerReceiver(mOnOffReceiver, new IntentFilter(FbTextApplication.SEND_INVITATION));
    registerReceiver(mOnOffReceiver, new IntentFilter(FbTextApplication.UPDATE_USER_STATE));
    registerReceiver(mOnOffReceiver, new IntentFilter(FbTextApplication.PUSH_NOTIFICATION_FAVORITE_ONLINE));
    registerReceiver(mOnOffReceiver, new IntentFilter(FbTextApplication.CHANGE_STATUS));
    mSettings = PreferenceManager.getDefaultSharedPreferences(this);
    mSettings.registerOnSharedPreferenceChangeListener(mPreferenceListener);
    if (mSettings.getBoolean(FbTextApplication.USE_AUTO_AWAY_KEY, false)) {
        mOnOffReceiverIsRegistered = true;
        registerReceiver(mOnOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF));
        registerReceiver(mOnOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_ON));
        // registerReceiver(sma, filter)
    }
    String tmpJid = mSettings.getString(FbTextApplication.ACCOUNT_USERNAME_KEY, "").trim();
    mLogin = StringUtils.parseName(tmpJid);
    boolean useSystemAccount = mSettings.getBoolean(FbTextApplication.USE_SYSTEM_ACCOUNT_KEY, false);
    mPort = DEFAULT_XMPP_PORT;
    mService = StringUtils.parseServer(tmpJid);
    mHost = mService;
    initMemorizingTrustManager();

    if (mSettings.getBoolean(FbTextApplication.ACCOUNT_SPECIFIC_SERVER_KEY, false)) {
        mHost = mSettings.getString(FbTextApplication.ACCOUNT_SPECIFIC_SERVER_HOST_KEY, "").trim();
        if ("".equals(mHost))
            mHost = mService;
        String tmpPort = mSettings.getString(FbTextApplication.ACCOUNT_SPECIFIC_SERVER_PORT_KEY, "5222");
        if (!"".equals(tmpPort))
            mPort = Integer.parseInt(tmpPort);
    }
    if (mSettings.getBoolean(FbTextApplication.FULL_JID_LOGIN_KEY, false) || "gmail.com".equals(mService)
            || "googlemail.com".equals(mService) || useSystemAccount) {
        mLogin = tmpJid;
    }

    configure(ProviderManager.getInstance());

    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    Roster.setDefaultSubscriptionMode(SubscriptionMode.manual);
    mBind = new XmppFacade(this);
    if (FbTextApplication.isDebug)
        Log.d(TAG, "Create FacebookTextService \t id: " + mLogin + " \t host: " + mHost + "\tmPort" + mPort
                + "\t service" + mService);
}

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

private void sendMMS(final byte[] bytesToSend) {
    revokeWifi(true);/* ww w .j ava 2 s  .co m*/

    // enable mms connection to mobile data
    mConnMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    int result = beginMmsConnectivity();

    if (LOCAL_LOGV)
        Log.v(TAG, "result of connectivity: " + result + " ");

    if (result != 0) {
        // 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;
                }

                @SuppressWarnings("deprecation")
                NetworkInfo mNetworkInfo = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);

                if ((mNetworkInfo == null) || (mNetworkInfo.getType() != ConnectivityManager.TYPE_MOBILE)) {
                    return;
                }

                if (!mNetworkInfo.isConnected()) {
                    return;
                } else {
                    // ready to send the message now
                    if (LOCAL_LOGV)
                        Log.v(TAG, "sending through broadcast receiver");
                    alreadySending = true;
                    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 {
                        if (LOCAL_LOGV)
                            Log.v(TAG, "sending through handler");
                        context.unregisterReceiver(receiver);
                    } catch (Exception e) {

                    }

                    sendData(bytesToSend);
                }
            }
        }, 7000);
    } else {
        // mms connection already active, so send the message
        if (LOCAL_LOGV)
            Log.v(TAG, "sending right away, already ready");
        sendData(bytesToSend);
    }
}

From source file:com.nbplus.vbroadlauncher.fragment.LauncherFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    try {/*w  ww.  jav  a2s.co  m*/
        Log.d(TAG, "LauncherFragment onAttach()");
        ((HomeLauncherActivity) getActivity()).registerActivityInteractionListener(this);

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

        intentFilter = new IntentFilter();
        intentFilter.addAction(Constants.ACTION_SET_VILLAGE_NAME);
        intentFilter.addAction(IoTConstants.ACTION_IOT_DATA_SYNC_COMPLETED);
        intentFilter.addAction(IoTConstants.ACTION_IOT_SERVICE_STATUS_CHANGED);
        intentFilter.addAction(PushConstants.ACTION_PUSH_STATUS_CHANGED);
        intentFilter.addAction(PushConstants.ACTION_PUSH_MESSAGE_RECEIVED);
        LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mBroadcastReceiver, intentFilter);

        mHandler = new LauncherFragmentHandler(this);
    } catch (ClassCastException e) {
        throw new ClassCastException(activity.toString() + " must implement OnFragmentInteractionListener");
    }
}

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

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

    MenuDrawer.updateDrawer(mMenuDrawer, this);

    if (mSlidingUpPanelLayout.getPanelState() == SlidingUpPanelLayout.PanelState.HIDDEN) {
        mPlaybackPanel.setVisibility(View.GONE);
    } else {/*from  www .  j  av  a2  s.  c o m*/
        mPlaybackPanel.setup(mSlidingUpPanelLayout.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED);
        mPlaybackPanel.setVisibility(View.VISIBLE);
        if (mSlidingUpPanelLayout.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) {
            mPanelSlideListener.onPanelSlide(mSlidingUpPanelLayout, 1f);
        } else {
            mPanelSlideListener.onPanelSlide(mSlidingUpPanelLayout, 0f);
        }
    }

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

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

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

    // Install listener that disables the navigation drawer and hides the actionbar whenever
    // a WelcomeFragment or ContextMenuFragment is the currently shown Fragment.
    getSupportFragmentManager().addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
        @Override
        public void onBackStackChanged() {
            updateActionBarState(true);
        }
    });
    updateActionBarState(true);

}