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:com.avalond.ad_blocak.vpn.AdVpnService.java

private void startVpn(PendingIntent notificationIntent) {
    notificationBuilder.setContentTitle(getString(R.string.notification_title));
    if (notificationIntent != null) {
        notificationBuilder.setContentIntent(notificationIntent);
    }/*from   ww  w  .  ja v  a  2  s  .  co  m*/
    updateVpnStatus(VPN_STATUS_STARTING);

    registerReceiver(connectivityChangedReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));

    restartVpnThread();
}

From source file:com.marianhello.bgloc.LocationService.java

@Override
public void onCreate() {
    super.onCreate();
    log = LoggerManager.getLogger(LocationService.class);
    log.info("Creating LocationService");

    // An Android handler thread internally operates on a looper.
    handlerThread = new HandlerThread("LocationService.HandlerThread");
    handlerThread.start();//from www  .  ja  v  a2  s  . c om
    // An Android service handler is a handler running on a specific background thread.
    serviceHandler = new ServiceHandler(handlerThread.getLooper());

    dao = (DAOFactory.createLocationDAO(this));
    syncAccount = AccountHelper.CreateSyncAccount(this,
            AuthenticatorService.getAccount(getStringResource(Config.ACCOUNT_TYPE_RESOURCE)));

    registerReceiver(connectivityChangeReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
}

From source file:org.bcsphere.activity.BCPage.java

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

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
    intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    mActivity.registerReceiver(mReceiver, intentFilter);
}

From source file:org.protocoder.MainActivity.java

/**
* onResume/* w  w  w .ja  v  a 2  s  .  c o m*/
*/
@Override
protected void onResume() {
    super.onResume();

    //set settings
    setScreenAlwaysOn(SettingsFragment.getScreenOn(this));

    MLog.d(TAG, "Registering as an EventBus listener in MainActivity");
    EventBus.getDefault().register(this);

    mStopServerReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            mProtocoder.app.hardKillConnections();
        }
    };

    registerReceiver(connectivityChangeReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));

    mProtocoder.app.startServers();
    IntentFilter filterSend = new IntentFilter();
    filterSend.addAction("org.protocoder.intent.action.STOP_SERVER");
    registerReceiver(mStopServerReceiver, filterSend);
    observer.startWatching();

    try {
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");

        if (menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Exception e) {
        // presumably, not relevant
    }

    IDEcommunication.getInstance(this).ready(false);
}

From source file:net.primeranks.fs_viewer.fs_replay.EntryPointActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.entry_point);

    ListView listView = getListView();
    listView.setOnItemClickListener(this);

    // Add a back to top button on the bottom       - Create the item
    backToTop_footer = (Button) getLayoutInflater().inflate(R.layout.user_footer, null);
    backToTop_footer.setCompoundDrawablesWithIntrinsicBounds(
            getResources().getDrawable(android.R.drawable.ic_menu_upload), null, null, null);
    backToTop_footer.setVisibility(View.INVISIBLE); // While empty do not show it
    headerUser = getLayoutInflater().inflate(R.layout.user_header, null);
    listView.addFooterView(backToTop_footer, null, true); // Add it to the bottom
    listView.addHeaderView(headerUser, null, false);

    userList = new ArrayList<User>(); // Start with an empty one
    this.userAdapter = new UserAdapter(this, userList);
    listView.setAdapter(this.userAdapter);
    listView.setItemsCanFocus(false);/*  w w  w. j  av a  2s  .c o  m*/

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

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

@Override
public void onCreate() {
    Log.d(THIS_FILE, "Download Lib Service started");

    prefs = PreferenceManager.getDefaultSharedPreferences(this);
    // Lock wifi if possible to ensure download will be done
    wifiLock = ((WifiManager) getSystemService(WIFI_SERVICE))
            .createWifiLock("com.csipsimple.service.DownloadLibService");
    connectivityManager = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
    connectionChangeReceiver = new ConnectionChangeReceiver();
    registerReceiver(connectionChangeReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
    NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
    if (activeNetwork != null) {
        NetworkInfo.State state = activeNetwork.getState();
        connected = (state == NetworkInfo.State.CONNECTED || state == NetworkInfo.State.SUSPENDED);
    } else {//from   w w  w .java2 s .  c o  m
        connected = false;
    }

}

From source file:org.zoumbox.mh_dla_notifier.Receiver.java

@Override
public void onReceive(Context context, Intent intent) {

    String intentAction = intent.getAction();
    Log.d(TAG, String.format("<<< %s#onReceive action=%s", getClass().getName(), intentAction));

    boolean connectivityChanged = ConnectivityManager.CONNECTIVITY_ACTION.equals(intentAction);
    boolean justGotConnection = false;
    if (connectivityChanged) {

        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();

        justGotConnection = activeNetwork != null && activeNetwork.isConnected();
        Log.d(TAG, "Connectivity change. isConnected=" + justGotConnection);
    }/*from w  w  w  . j  a  v  a 2 s. co m*/

    if (connectivityChanged && !justGotConnection) {
        Log.d(TAG, "Just lost connectivity, nothing to do");
        return;
    }

    String trollId = intent.getStringExtra(Alarms.EXTRA_TROLL_ID);
    if (Strings.isNullOrEmpty(trollId)) {
        Set<String> trollIds = getProfileProxy().getTrollIds(context);
        if (trollIds.isEmpty()) {
            Log.d(TAG, "No troll registered, exiting...");
            return;
        }
        trollId = trollIds.iterator().next();
        Log.d(TAG, "TrollId not defined, using the fist one: " + trollId);
    }

    if (!getProfileProxy().isPasswordDefined(context, trollId)) {
        Log.d(TAG, "Troll password is not defined, exiting...");
        return;
    }

    // If type is provided, request for an update
    String type = intent.getStringExtra(Alarms.EXTRA_TYPE);
    boolean requestUpdate = !Strings.isNullOrEmpty(type);

    // If device just started, request for wakeups registration
    boolean requestAlarmRegistering = justRestarted().apply(context);

    // Just go the internet connection back. Update will be necessary if
    //  - device restarted since last update and last update in more than 2 hours ago
    //  - last update failed because of network error
    if (!requestUpdate && justGotConnection) { // !requestUpdate because no need to check if update is already requested
        requestUpdate = Predicates
                .or(shouldUpdateBecauseOfRestart(trollId), shouldUpdateBecauseOfNetworkFailure(trollId))
                .apply(context);
    }

    Log.d(TAG, String.format("requestUpdate=%b ; requestAlarmRegistering=%b", requestUpdate,
            requestAlarmRegistering));

    // FIXME AThimel 14/02/14 Remove ASAP
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    try {
        Troll troll = getProfileProxy().fetchTrollWithoutUpdate(context, trollId).left();
        if (requestUpdate) {
            // If the current DLA already has no more PA, skip update
            boolean skipUpdate = false;
            if (AlarmType.CURRENT_DLA.name().equals(type)) {
                skipUpdate = troll.getPa() == 0 && MhDlaNotifierUtils.IS_IN_THE_FUTURE.apply(troll.getDla());
            }
            if (skipUpdate) {
                trollLoaded(troll, context, false);
            } else {
                refreshDla(context, trollId);
            }
        } else if (requestAlarmRegistering) {
            trollLoaded(troll, context, false);
        } else {
            Log.d(TAG, "Skip loading Troll");
        }
    } catch (MissingLoginPasswordException mde) {
        Log.w(TAG, "Missing trollId and/or password, exiting...");
    }
}

From source file:com.classiqo.nativeandroid_32bitz.ui.MediaBrowserFragment.java

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

    MediaBrowserCompat mediaBrowser = mMediaFragmentListener.getMediaBrowser();

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

    if (mediaBrowser.isConnected()) {
        onConnected();//  ww  w  .  jav a2 s .com
    }

    this.getActivity().registerReceiver(mConnectivityChangeReceiver,
            new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
}

From source file:org.jak_linux.dns66.vpn.AdVpnService.java

private void startVpn(PendingIntent notificationIntent) {
    notificationBuilder.setContentTitle(getString(R.string.notification_title));
    if (notificationIntent != null)
        notificationBuilder.setContentIntent(notificationIntent);
    updateVpnStatus(VPN_STATUS_STARTING);

    registerReceiver(connectivityChangedReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));

    restartVpnThread();/*w  ww  .  j a v  a 2  s  .co m*/
}

From source file:online.privacy.SetupActivity.java

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

    // Register the IntentService Listeners to get the response of the user check and location list.
    IntentFilter verifyFilter = new IntentFilter(VerifyUserAccountReceiver.API_RESPONSE);
    verifyFilter.addCategory(Intent.CATEGORY_DEFAULT);
    verifyReceiver = new VerifyUserAccountReceiver();
    registerReceiver(verifyReceiver, verifyFilter);

    // Register the NetworkReceiver to listen for changes to connectivity.
    IntentFilter networkChangeFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
    networkReceiver = new NetworkReceiver();
    this.registerReceiver(networkReceiver, networkChangeFilter);

    // Populate the Location list.
    VPNLocations vpnLocations = new VPNLocations(this);
    ArrayList<VPNLocation> locationList = vpnLocations.getArrayList();
    final VPNLocationAdapter locationAdapter = new VPNLocationAdapter(this, R.layout.spinner_layout_full,
            locationList);/* ww  w .j  a va 2 s . c  o  m*/
    PrivacyOnlineUtility utility = new PrivacyOnlineUtility();
    utility.updateSpinnerValues(activitySetup, R.id.input_spinner_default_vpn_location, locationAdapter, false,
            new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
                    VPNLocation location = locationAdapter.getItem(position);
                    defaultVPNLocationUpdate = location.getHostname();
                }

                @Override
                public void onNothingSelected(AdapterView<?> adapter) {
                }
            });
}