List of usage examples for android.net ConnectivityManager EXTRA_REASON
String EXTRA_REASON
To view the source code for android.net ConnectivityManager EXTRA_REASON.
Click Source Link
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,//from ww w . jav a 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:com.prey.events.factories.EventFactory.java
public static Event getEvent(Context ctx, Intent intent) { String message = "getEvent[" + intent.getAction() + "]"; PreyLogger.d(message);//www .jav a 2 s . c o m if (BOOT_COMPLETED.equals(intent.getAction())) { notification(ctx); if (PreyConfig.getPreyConfig(ctx).isSimChanged()) { JSONObject info = new JSONObject(); try { info.put("new_phone_number", PreyTelephonyManager.getInstance(ctx).getLine1Number()); } catch (Exception e) { } return new Event(Event.SIM_CHANGED, info.toString()); } else { return new Event(Event.TURNED_ON); } } if (ACTION_SHUTDOWN.equals(intent.getAction())) { return new Event(Event.TURNED_OFF); } if (BATTERY_LOW.equals(intent.getAction())) { return new Event(Event.BATTERY_LOW); } if (CONNECTIVITY_CHANGE.equals(intent.getAction())) { JSONObject info = new JSONObject(); int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN); PreyLogger.d("__wifiState:" + wifiState); try { boolean connected = false; if (!PreyConnectivityManager.getInstance(ctx).isWifiConnected()) { Bundle extras = intent.getExtras(); if (extras != null) { if ("connected".equals(extras.getString(ConnectivityManager.EXTRA_REASON))) { connected = true; } } } if (!PreyConnectivityManager.getInstance(ctx).isMobileConnected()) { info.put("connected", "mobile"); if (wifiState == WifiManager.WIFI_STATE_ENABLED) { connected = true; } } if (connected) { try { Thread.sleep(4000); } catch (Exception e) { } PreyConfig.getPreyConfig(ctx).registerC2dm(); Intent intentFile = new Intent(ctx, FileretrievalService.class); ctx.startService(intentFile); } } catch (Exception e) { } return new Event(Event.WIFI_CHANGED, info.toString()); } if (WIFI_STATE_CHANGED.equals(intent.getAction())) { JSONObject info = new JSONObject(); int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN); PreyLogger.d("___wifiState:" + wifiState); try { if (wifiState == WifiManager.WIFI_STATE_ENABLED) { info.put("connected", "wifi"); try { Thread.sleep(2000); } catch (Exception e) { } PreyConfig.getPreyConfig(ctx).registerC2dm(); Intent intentFile = new Intent(ctx, FileretrievalService.class); ctx.startService(intentFile); } } catch (Exception e) { } return new Event(Event.WIFI_CHANGED, info.toString()); } if (AIRPLANE_MODE.equals(intent.getAction())) { if (!isAirplaneModeOn(ctx)) { notification(ctx); boolean connected = false; if (!PreyConnectivityManager.getInstance(ctx).isWifiConnected()) { Bundle extras = intent.getExtras(); if (extras != null) { if ("connected".equals(extras.getString(ConnectivityManager.EXTRA_REASON))) { connected = true; } } } if (!PreyConnectivityManager.getInstance(ctx).isMobileConnected()) { int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN); if (wifiState == WifiManager.WIFI_STATE_ENABLED) { connected = true; } } if (connected) { PreyBetaController.startPrey(ctx); PreyConfig.getPreyConfig(ctx).registerC2dm(); Intent intentFile = new Intent(ctx, FileretrievalService.class); ctx.startService(intentFile); } } } return null; }
From source file:com.github.marcosalis.kraken.utils.network.NetworkBroadcastReceiver.java
private void logNetworkInfo(@Nonnull 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 w w .j a v a 2 s . c om*/ "Network info: " + " otherNetworkInfo = " + (otherNetworkInfo == null ? "[none]" : otherNetworkInfo) + ", failover=" + failover + ", reason=" + reason); } }
From source file:com.futureplatforms.kirin.extensions.networking.NetworkingBackend.java
private void listenForChangeInNetworkStatus() { Log.i(C.TAG, "NetworkingBackend.listenForChangeInNetworkStatus: "); mReceiver = new BroadcastReceiver() { @Override/*w ww. j av a2 s . co m*/ 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)); }