List of usage examples for android.net ConnectivityManager EXTRA_NO_CONNECTIVITY
String EXTRA_NO_CONNECTIVITY
To view the source code for android.net ConnectivityManager EXTRA_NO_CONNECTIVITY.
Click Source Link
From source file:com.google.android.apps.muzei.NetworkChangeReceiver.java
@Override public void onReceive(Context context, Intent intent) { if (intent == null || !ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) { return;/*from w w w. j a v a 2 s .c om*/ } boolean hasConnectivity = !intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false); if (hasConnectivity) { EventBus.getDefault().post(new GainedNetworkConnectivityEvent()); // Check with components that may not currently be alive but interested in // network connectivity changes. Intent retryIntent = ArtworkCache.maybeRetryDownloadDueToGainedConnectivity(context); if (retryIntent != null) { startWakefulService(context, retryIntent); } // TODO: wakeful broadcast? SourceManager sm = SourceManager.getInstance(context); sm.maybeDispatchNetworkAvailable(); } }
From source file:com.github.marcosalis.kraken.utils.network.NetworkBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { logNetworkInfo(intent);/*w w w . j a v a 2s. c om*/ // use EXTRA_NO_CONNECTIVITY to check if there is no connection if (intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false)) { notifyConnectionGone(context); return; } final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo netInfo = cm.getActiveNetworkInfo(); // send local broadcast to notify all registered receivers if (netInfo != null && netInfo.isConnected()) { // connection active notifyConnectionActive(context, netInfo.getType()); } else { // connection has gone notifyConnectionGone(context); } }
From source file:com.github.luluvise.droid_utils.lib.network.NetworkBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { if (DroidConfig.DEBUG) { // debugging network info final NetworkInfo otherNetworkInfo = (NetworkInfo) intent .getParcelableExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO); final String reason = intent.getStringExtra(ConnectivityManager.EXTRA_REASON); final boolean failover = intent.getBooleanExtra(ConnectivityManager.EXTRA_IS_FAILOVER, false); Log.i(TAG,/* w ww . j ava 2 s. c o m*/ "onReceive(): " + " otherNetworkInfo = " + (otherNetworkInfo == null ? "[none]" : otherNetworkInfo) + ", failover=" + failover + ", reason=" + reason); } // use EXTRA_NO_CONNECTIVITY to check if there is no connection if (intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false)) { notifyConnectionGone(context); return; } final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo netInfo = cm.getActiveNetworkInfo(); // send local broadcast to notify all registered receivers if (netInfo != null && netInfo.isConnected()) { // connection active notifyConnectionActive(context, netInfo.getType()); } else { // connection has gone notifyConnectionGone(context); } }
From source file:net.sf.aria2.Aria2Service.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (isRunning()) throw new IllegalStateException("Can not start aria2: running instance already exists!"); unregisterOldReceiver();/*from w w w.ja va 2 s . c o m*/ final ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); final NetworkInfo ni = cm.getActiveNetworkInfo(); if (ni != null && ni.isConnectedOrConnecting()) startAria2(Config.from(intent)); else { if (intent.hasExtra(Config.EXTRA_INTERACTIVE)) Toast.makeText(getApplicationContext(), getText(R.string.will_start_later), Toast.LENGTH_LONG) .show(); else { receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.hasExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY) && intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false)) return; startAria2(Config.from(intent)); unregisterReceiver(this); receiver = null; } }; registerReceiver(receiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); } } return super.onStartCommand(intent, flags, startId); }
From source file:org.wso2.iot.agent.services.AgentStartupReceiver.java
private boolean isNetworkConnected(Context context, Intent intent) { if (intent.getExtras() != null) { final ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo ni = connectivityManager.getActiveNetworkInfo(); if (ni != null && ni.isConnectedOrConnecting()) { if (Constants.DEBUG_MODE_ENABLED) { Log.d(TAG, "Network " + ni.getTypeName() + " connected"); }//ww w . ja va 2 s. c o m return true; } else if (intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, Boolean.FALSE)) { Log.i(TAG, "There's no network connectivity"); } } return false; }
From source file:ar.com.iron.android.extensions.connections.InetDataClient.java
/** * Invocado cuando hay cambios de conectividad en la plataforma * //from w w w.j av a 2s.c o m * @param intent * Intent con los datos del cambio */ protected void onConnectivityChanged(Intent intent) { boolean connectivityLoosed = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false); boolean hadConnectivity = this.hasConnectivity.get(); this.hasConnectivity.set(!connectivityLoosed); if (connectivityListener != null && hadConnectivity == connectivityLoosed) { // Es un cambio de estado, tenemos que notificarlo NetworkInfo network = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO); connectivityListener.onConnectivityChanged(!connectivityLoosed, network); } }
From source file:com.avalond.ad_blocak.vpn.AdVpnService.java
private void connectivityChanged(Intent intent) { if (intent.getIntExtra(ConnectivityManager.EXTRA_NETWORK_TYPE, 0) == ConnectivityManager.TYPE_VPN) { Log.i(TAG, "Ignoring connectivity changed for our own network"); return;//from w w w . j a v a 2s.c o m } if (!ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) { Log.e(TAG, "Got bad intent on connectivity changed " + intent.getAction()); } if (intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false)) { Log.i(TAG, "Connectivity changed to no connectivity, wait for a network"); waitForNetVpn(); } else { Log.i(TAG, "Network changed, try to reconnect"); reconnect(); } }
From source file:com.cerema.cloud2.files.InstantUploadBroadcastReceiver.java
private void handleConnectivityAction(Context context, Intent intent) { if (!instantPictureUploadEnabled(context)) { Log_OC.d(TAG, "Instant upload disabled, don't upload anything"); return;//from w w w.ja v a 2 s . c o m } if (instantPictureUploadViaWiFiOnly(context) && !isConnectedViaWiFi(context)) { Account account = AccountUtils.getCurrentOwnCloudAccount(context); if (account == null) { Log_OC.w(TAG, "No account found for instant upload, aborting"); return; } Intent i = new Intent(context, FileUploader.class); i.putExtra(FileUploader.KEY_ACCOUNT, account); i.putExtra(FileUploader.KEY_CANCEL_ALL, true); context.startService(i); } if (!intent.hasExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY) && isOnline(context) && (!instantPictureUploadViaWiFiOnly(context) || (instantPictureUploadViaWiFiOnly(context) == isConnectedViaWiFi(context) == true))) { DbHandler db = new DbHandler(context); Cursor c = db.getAwaitingFiles(); if (c.moveToFirst()) { do { if (instantPictureUploadViaWiFiOnly(context) && !isConnectedViaWiFi(context)) { break; } String account_name = c.getString(c.getColumnIndex("account")); String file_path = c.getString(c.getColumnIndex("path")); File f = new File(file_path); if (f.exists()) { Account account = new Account(account_name, MainApp.getAccountType()); String mimeType = null; try { mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension( f.getName().substring(f.getName().lastIndexOf('.') + 1)); } catch (Throwable e) { Log_OC.e(TAG, "Trying to find out MIME type of a file without extension: " + f.getName()); } if (mimeType == null) mimeType = "application/octet-stream"; Intent i = new Intent(context, FileUploader.class); i.putExtra(FileUploader.KEY_ACCOUNT, account); i.putExtra(FileUploader.KEY_LOCAL_FILE, file_path); i.putExtra(FileUploader.KEY_REMOTE_FILE, FileStorageUtils.getInstantUploadFilePath(context, f.getName())); i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE); i.putExtra(FileUploader.KEY_INSTANT_UPLOAD, true); // instant upload behaviour i = addInstantUploadBehaviour(i, context); context.startService(i); } else { Log_OC.w(TAG, "Instant upload file " + f.getAbsolutePath() + " dont exist anymore"); } } while (c.moveToNext()); } c.close(); db.close(); } }
From source file:com.futureplatforms.kirin.extensions.networking.NetworkingBackend.java
private void listenForChangeInNetworkStatus() { Log.i(C.TAG, "NetworkingBackend.listenForChangeInNetworkStatus: "); mReceiver = new BroadcastReceiver() { @Override/*from w w w . j ava 2 s.c om*/ public void onReceive(Context context, Intent intent) { if (intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false)) { String reason = intent.getStringExtra(ConnectivityManager.EXTRA_REASON); if (reason == null || reason.trim().length() == 0) { reason = mContext.getString(R.string.networking_connection_lost); } cancelAllDownloads(reason); } } }; mContext.registerReceiver(mReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); }
From source file:at.alladin.rmbt.android.main.RMBTMainActivity.java
/** * *//*from www . ja v a2 s . com*/ @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); } } }; }