List of usage examples for android.net.wifi WifiManager NETWORK_STATE_CHANGED_ACTION
String NETWORK_STATE_CHANGED_ACTION
To view the source code for android.net.wifi WifiManager NETWORK_STATE_CHANGED_ACTION.
Click Source Link
From source file:com.vonglasow.michael.satstat.GpsEventReceiver.java
@Override public void onReceive(Context context, Intent intent) { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); // some logic to use the pre-1.7 setting KEY_PREF_UPDATE_WIFI as a // fallback if KEY_PREF_UPDATE_NETWORKS is not set Set<String> fallbackUpdateNetworks = new HashSet<String>(); if (sharedPref.getBoolean(Const.KEY_PREF_UPDATE_WIFI, false)) { fallbackUpdateNetworks.add(Const.KEY_PREF_UPDATE_NETWORKS_WIFI); }/* w w w . java2s . c om*/ Set<String> updateNetworks = sharedPref.getStringSet(Const.KEY_PREF_UPDATE_NETWORKS, fallbackUpdateNetworks); if (intent.getAction().equals(Const.GPS_ENABLED_CHANGE) || intent.getAction().equals(Const.GPS_ENABLED_CHANGE)) { //FIXME: why are we checking for the same intent twice? Should on of them be GPS_FIX_CHANGE? // an application has connected to GPS or disconnected from it, check if notification needs updating boolean notifyFix = sharedPref.getBoolean(Const.KEY_PREF_NOTIFY_FIX, false); boolean notifySearch = sharedPref.getBoolean(Const.KEY_PREF_NOTIFY_SEARCH, false); if (notifyFix || notifySearch) { boolean isRunning = false; ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (PasvLocListenerService.class.getName().equals(service.service.getClassName())) { isRunning = true; } } if (!isRunning) { Intent startServiceIntent = new Intent(context, PasvLocListenerService.class); startServiceIntent.setAction(intent.getAction()); startServiceIntent.putExtras(intent.getExtras()); context.startService(startServiceIntent); } } } else if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION) && updateNetworks.contains(Const.KEY_PREF_UPDATE_NETWORKS_WIFI)) { // change in WiFi connectivity, check if we are connected and need to refresh AGPS //FIXME: KEY_PREF_UPDATE_WIFI as fallback only NetworkInfo netinfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); if (netinfo == null) return; if (!netinfo.isConnected()) return; //Toast.makeText(context, "WiFi is connected", Toast.LENGTH_SHORT).show(); Log.i(this.getClass().getSimpleName(), "WiFi is connected"); refreshAgps(context, true, false); } else if ((intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) || (intent.getAction().equals(Const.AGPS_DATA_EXPIRED))) { // change in network connectivity or AGPS expiration timer fired boolean isAgpsExpired = false; if (intent.getAction().equals(Const.AGPS_DATA_EXPIRED)) { Log.i(this.getClass().getSimpleName(), "AGPS data expired, checking available networks"); isAgpsExpired = true; } NetworkInfo netinfo = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE)) .getActiveNetworkInfo(); if (netinfo == null) return; if (!netinfo.isConnected()) return; String type; if ((netinfo.getType() < ConnectivityManager.TYPE_MOBILE_MMS) || (netinfo.getType() > ConnectivityManager.TYPE_MOBILE_HIPRI)) { type = Integer.toString(netinfo.getType()); } else { // specific mobile data connections will be treated as TYPE_MOBILE type = Const.KEY_PREF_UPDATE_NETWORKS_MOBILE; } if (!updateNetworks.contains(type)) return; if (!isAgpsExpired) Log.i(this.getClass().getSimpleName(), "Network of type " + netinfo.getTypeName() + " is connected"); // Enforce the update interval if we were called by a network event // but not if we were called by a timer, because in that case the // check has already been done. (I am somewhat paranoid and don't // count on alarms not going off a few milliseconds too early.) refreshAgps(context, !isAgpsExpired, false); } }
From source file:com.github.sryze.wirebug.MainActivity.java
@Override protected void onResume() { super.onResume(); boolean isConnected = NetworkUtils.isConnectedToWifi(connectivityManager); connectedView.setVisibility(isConnected ? View.VISIBLE : View.GONE); notConnectedView.setVisibility(isConnected ? View.GONE : View.VISIBLE); boolean isEnabled = DebugManager.isTcpDebuggingEnabled(); updateInstructions(isEnabled);//ww w. j a v a2 s .c o m updateStatus(); toggleDebuggingButton.setOnCheckedChangeListener(null); toggleDebuggingButton.setChecked(isEnabled); toggleDebuggingButton.setOnCheckedChangeListener(enableSwitchChangeListener); networkStateChangedReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Log.d(TAG, "Received network state changed broadcast"); NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); switch (networkInfo.getState()) { case CONNECTED: connectedView.setVisibility(View.VISIBLE); notConnectedView.setVisibility(View.INVISIBLE); break; case DISCONNECTED: connectedView.setVisibility(View.GONE); notConnectedView.setVisibility(View.VISIBLE); break; } updateConnectionInfo(); } }; registerReceiver(networkStateChangedReceiver, new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION)); debugStatusChangedReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Log.d(TAG, "Received debug state change broadcast"); boolean isEnabled = intent.getBooleanExtra(DebugStatusService.EXTRA_IS_ENABLED, false); updateInstructions(isEnabled); toggleDebuggingButton.setOnCheckedChangeListener(null); toggleDebuggingButton.setChecked(isEnabled); toggleDebuggingButton.setOnCheckedChangeListener(enableSwitchChangeListener); } }; registerReceiver(debugStatusChangedReceiver, new IntentFilter(DebugStatusService.ACTION_STATUS_CHANGED)); }
From source file:org.deviceconnect.android.deviceplugin.irkit.IRKitDeviceService.java
@Override public int onStartCommand(final Intent intent, final int flags, final int startId) { if (intent != null) { String action = intent.getAction(); if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) { if (!WiFiUtil.isOnWiFi(this) && IRKitManager.INSTANCE.isDetecting()) { stopDetection();// w w w . j av a 2 s . co m } else if (WiFiUtil.isOnWiFi(this) && WiFiUtil.isChangedSSID(this, mCurrentSSID)) { restartDetection(); } return START_STICKY; } } return super.onStartCommand(intent, flags, startId); }
From source file:org.sufficientlysecure.keychain.ui.transfer.view.TransferFragment.java
@Override public void onResume() { super.onResume(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); getContext().registerReceiver(broadcastReceiver, intentFilter); }
From source file:org.span.manager.MainActivity.java
@Override public void onResume() { super.onResume(); Log.d(TAG, "onResume()"); // DEBUG // check if the battery temperature should be displayed if (app.prefs.getString("batterytemppref", "fahrenheit").equals("disabled") == false) { // create the IntentFilter that will be used to listen // to battery status broadcasts intentFilter = new IntentFilter(); intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED); registerReceiver(intentReceiver, intentFilter); batteryTemperatureLayout.setVisibility(View.VISIBLE); } else {/*from ww w .j av a 2 s .c o m*/ try { unregisterReceiver(this.intentReceiver); } catch (Exception e) { ; } batteryTemperatureLayout.setVisibility(View.INVISIBLE); } // Register to receive updates about the device network state registerReceiver(intentReceiver, new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION)); registerReceiver(intentReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); /* Window window = getWindow(); // window.addFlags(LayoutParams.FLAG_DISMISS_KEYGUARD); // window.addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED); window.addFlags(LayoutParams.FLAG_TURN_SCREEN_ON); window.addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON); */ }
From source file:de.j4velin.wifiAutoOff.Preferences.java
@Override public void onResume() { super.onResume(); final CheckBoxPreference no_network_off = (CheckBoxPreference) findPreference("off_no_network"); no_network_off.setSummary(getString(R.string.for_at_least, PreferenceManager .getDefaultSharedPreferences(this).getInt("no_network_timeout", Receiver.TIMEOUT_NO_NETWORK))); handler.postDelayed(signalUpdater, 1000); IntentFilter ifilter = new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION); ifilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); registerReceiver(stateChangedReceiver, ifilter); }
From source file:com.connectsdk.discovery.DiscoveryManager.java
/** * Create a new instance of DiscoveryManager. * Direct use of this constructor is not recommended. In most cases, * you should use DiscoveryManager.getInstance() instead. *//*from w ww. j a v a 2s . c o m*/ public DiscoveryManager(Context context, ConnectableDeviceStore connectableDeviceStore) { this.context = context; this.connectableDeviceStore = connectableDeviceStore; allDevices = new ConcurrentHashMap<String, ConnectableDevice>(8, 0.75f, 2); compatibleDevices = new ConcurrentHashMap<String, ConnectableDevice>(8, 0.75f, 2); deviceClasses = new ConcurrentHashMap<String, Class<? extends DeviceService>>(4, 0.75f, 2); discoveryProviders = new CopyOnWriteArrayList<DiscoveryProvider>(); discoveryListeners = new CopyOnWriteArrayList<DiscoveryManagerListener>(); WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); multicastLock = wifiMgr.createMulticastLock("Connect SDK"); multicastLock.setReferenceCounted(true); capabilityFilters = new ArrayList<CapabilityFilter>(); pairingLevel = PairingLevel.OFF; receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) { NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); switch (networkInfo.getState()) { case CONNECTED: if (mSearching) { for (DiscoveryProvider provider : discoveryProviders) { provider.start(); } } break; case DISCONNECTED: Log.w("Connect SDK", "Network connection is disconnected"); for (DiscoveryProvider provider : discoveryProviders) { provider.reset(); } allDevices.clear(); for (ConnectableDevice device : compatibleDevices.values()) { handleDeviceLoss(device); } compatibleDevices.clear(); for (DiscoveryProvider provider : discoveryProviders) { provider.stop(); } break; case CONNECTING: break; case DISCONNECTING: break; case SUSPENDED: break; case UNKNOWN: break; } } } }; registerBroadcastReceiver(); }
From source file:net.majorkernelpanic.spydroid.ui.HandsetFragment.java
@Override public void onResume() { super.onResume(); if (!SessionManager.getManager().isStreaming()) displayIpAddress();/*from w w w. j av a2 s. c o m*/ else streamingState(1); getActivity().registerReceiver(mWifiStateReceiver, new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION)); }
From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java
@Override public void onReceive(Context context, Intent intent) { mComtext = context;/*ww w .j a v a2s.c o m*/ String action = intent.getAction(); Log.i("sai", "onReceive: " + action); super.onReceive(context, intent); if (ACTION_ON_QUARTER_HOUR.equals(action) || Intent.ACTION_DATE_CHANGED.equals(action) || Intent.ACTION_TIMEZONE_CHANGED.equals(action) || Intent.ACTION_TIME_CHANGED.equals(action) || Intent.ACTION_LOCALE_CHANGED.equals(action)) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); if (appWidgetManager != null) { int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context)); for (int appWidgetId : appWidgetIds) { RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget); float ratio = WidgetUtils.getScaleRatio(context, null, appWidgetId); // SPRD for bug421127 add am/pm for widget WidgetUtils.setTimeFormat(widget, (int) context.getResources().getDimension(R.dimen.widget_label_font_size), R.id.the_clock); WidgetUtils.setClockSize(context, widget, ratio); //refreshAlarm(context, widget); appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget); } } if (!ACTION_ON_QUARTER_HOUR.equals(action)) { cancelAlarmOnQuarterHour(context); } startAlarmOnQuarterHour(context); } // cg sai.pan begin else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); if (appWidgetManager != null) { int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context)); for (int appWidgetId : appWidgetIds) { RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget); refreshBtStatus(context, widget); appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget); } } } else if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) { int wifiStatus = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0); Log.e("sai", "wifiStatus" + wifiStatus); AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); if (appWidgetManager != null) { int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context)); for (int appWidgetId : appWidgetIds) { RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget); if (WifiManager.WIFI_STATE_ENABLED == wifiStatus || WifiManager.WIFI_STATE_ENABLING == wifiStatus) { widget.setImageViewResource(R.id.wifi, R.drawable.status_wifi_on); } else { widget.setImageViewResource(R.id.wifi, R.drawable.status_wifi_off); } appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget); } } } else if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); if (appWidgetManager != null) { int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context)); for (int appWidgetId : appWidgetIds) { RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget); refreshWifiStatus(context, widget); } } } else if ("android.net.conn.CONNECTIVITY_CHANGE".equals(action)) { if (isNetworkConnected(context)) { Log.e("sai", "isNetworkConnected true"); requestLocation(context); } else { Log.e("sai", "isNetworkConnected false"); } } }