List of usage examples for android.net NetworkInfo getDetailedState
@Deprecated
public @NonNull DetailedState getDetailedState()
From source file:org.brandroid.openmanager.fragments.DialogHandler.java
private static String getNetworkInfoInfo(NetworkInfo info) { String ret = ""; ret += info.getSubtypeName() + "/ "; if (info.getState() != null) ret += "s=" + info.getState().name() + "/ "; if (info.getDetailedState() != null) ret += "d=" + info.getDetailedState().name() + "/ "; if (info.getExtraInfo() != null) ret += "e=" + info.getExtraInfo(); return ret;// www . jav a 2s . co m }
From source file:android_network.hetnet.vpn_service.Util.java
public static String getNetworkInfo(Context context) { StringBuilder sb = new StringBuilder(); ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ani = cm.getActiveNetworkInfo(); List<NetworkInfo> listNI = new ArrayList<>(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) listNI.addAll(Arrays.asList(cm.getAllNetworkInfo())); else/* w w w . j a v a 2 s . co m*/ for (Network network : cm.getAllNetworks()) { NetworkInfo ni = cm.getNetworkInfo(network); if (ni != null) listNI.add(ni); } for (NetworkInfo ni : listNI) { sb.append(ni.getTypeName()).append('/').append(ni.getSubtypeName()).append(' ') .append(ni.getDetailedState()) .append(TextUtils.isEmpty(ni.getExtraInfo()) ? "" : " " + ni.getExtraInfo()) .append(ni.getType() == ConnectivityManager.TYPE_MOBILE ? " " + Util.getNetworkGeneration(ni.getSubtype()) : "") .append(ni.isRoaming() ? " R" : "") .append(ani != null && ni.getType() == ani.getType() && ni.getSubtype() == ani.getSubtype() ? " *" : "") .append("\r\n"); } try { Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces(); if (nis != null) while (nis.hasMoreElements()) { NetworkInterface ni = nis.nextElement(); if (ni != null && !ni.isLoopback()) { List<InterfaceAddress> ias = ni.getInterfaceAddresses(); if (ias != null) for (InterfaceAddress ia : ias) sb.append(ni.getName()).append(' ').append(ia.getAddress().getHostAddress()) .append('/').append(ia.getNetworkPrefixLength()).append(' ') .append(ni.getMTU()).append(' ').append(ni.isUp() ? '^' : 'v') .append("\r\n"); } } } catch (Throwable ex) { sb.append(ex.toString()).append("\r\n"); } if (sb.length() > 2) sb.setLength(sb.length() - 2); return sb.toString(); }
From source file:com.ultrafunk.network_info.receiver.WifiStatusReceiver.java
private boolean isConnectionReady(Intent intent) { if (isConnected() && (intent.getExtras() != null)) { NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); if ((networkInfo != null) && (networkInfo.getDetailedState() == NetworkInfo.DetailedState.CONNECTED)) return true; }//from www . j av a 2 s.c o m return false; }
From source file:com.master.metehan.filtereagle.Util.java
public static String getNetworkInfo(Context context) { StringBuilder sb = new StringBuilder(); ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ani = cm.getActiveNetworkInfo(); List<NetworkInfo> listNI = new ArrayList<>(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) listNI.addAll(Arrays.asList(cm.getAllNetworkInfo())); else//from ww w. j a va 2 s . c o m for (Network network : cm.getAllNetworks()) { NetworkInfo ni = cm.getNetworkInfo(network); if (ni != null) listNI.add(ni); } for (NetworkInfo ni : listNI) { sb.append(ni.getTypeName()).append('/').append(ni.getSubtypeName()).append(' ') .append(ni.getDetailedState()) .append(TextUtils.isEmpty(ni.getExtraInfo()) ? "" : " " + ni.getExtraInfo()) .append(ni.getType() == ConnectivityManager.TYPE_MOBILE ? " " + Util.getNetworkGeneration(ni.getSubtype()) : "") .append(ni.isRoaming() ? " R" : "") .append(ani != null && ni.getType() == ani.getType() && ni.getSubtype() == ani.getSubtype() ? " *" : "") .append("\r\n"); } try { Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces(); if (nis != null) { sb.append("\r\n"); while (nis.hasMoreElements()) { NetworkInterface ni = nis.nextElement(); if (ni != null) { List<InterfaceAddress> ias = ni.getInterfaceAddresses(); if (ias != null) for (InterfaceAddress ia : ias) sb.append(ni.getName()).append(' ').append(ia.getAddress().getHostAddress()) .append('/').append(ia.getNetworkPrefixLength()).append(' ') .append(ni.getMTU()).append("\r\n"); } } } } catch (Throwable ex) { sb.append(ex.toString()).append("\r\n"); } if (sb.length() > 2) sb.setLength(sb.length() - 2); return sb.toString(); }
From source file:net.helff.wificonnector.WifiConnectivityReceiver.java
@Override public void onReceive(Context context, Intent intent) { Log.i(TAG, "action: " + intent.getAction()); if (intent.getAction().equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) { Intent locationIntent = new LocationIntent(); context.sendBroadcast(locationIntent); }//w w w .j a v a 2s .c om if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) { NetworkInfo networkInfo = (NetworkInfo) intent .getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO); Log.d(TAG, "got network_state_changed with detailed info: " + networkInfo == null ? "nothing" : networkInfo.getDetailedState().name()); if (networkInfo != null && networkInfo.isConnected() && networkInfo.getType() == ConnectivityManager.TYPE_WIFI) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean autoConnect = prefs.getBoolean("autoConnect", false); Log.d(TAG, "triggering WifiConnectivityService with autoConnect=" + autoConnect); int command = autoConnect ? WifiConnectivityService.COMMAND_AUTO_UNLOCK_CONNECTION : WifiConnectivityService.COMMAND_CHECK_CONNECTION; Intent msgIntent = new Intent(context, WifiConnectivityService.class); msgIntent.putExtra(WifiConnectivityService.INTENT_COMMAND, command); context.startService(msgIntent); } } if (intent.getAction().equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) { Log.d(TAG, "triggering WifiConnectivityService state changed"); Intent msgIntent = new Intent(context, WifiConnectivityService.class); msgIntent.putExtra(WifiConnectivityService.INTENT_COMMAND, WifiConnectivityService.COMMAND_REFRESH_STATUS); context.startService(msgIntent); } }
From source file:com.geniatech.client_phone.wifi.WifiStatusTest.java
private void handleNetworkStateChanged(NetworkInfo networkInfo) { if (mWifiManager.isWifiEnabled()) { String summary = Summary.get(this, mWifiManager.getConnectionInfo().getSSID(), networkInfo.getDetailedState()); mNetworkState.setText(summary);/*w ww.jav a 2s . co m*/ } }
From source file:com.android.providers.downloads.DownloadInfo.java
/** * Returns whether this download is allowed to use the network. */// ww w. jav a 2s . c o m public NetworkState checkCanUseNetwork(long totalBytes) { final NetworkInfo info = mSystemFacade.getActiveNetworkInfo(mUid); if (info == null || !info.isConnected()) { return NetworkState.NO_CONNECTION; } if (DetailedState.BLOCKED.equals(info.getDetailedState())) { return NetworkState.BLOCKED; } if (mSystemFacade.isNetworkRoaming() && !isRoamingAllowed()) { return NetworkState.CANNOT_USE_ROAMING; } if (mSystemFacade.isActiveNetworkMetered() && !mAllowMetered) { return NetworkState.TYPE_DISALLOWED_BY_REQUESTOR; } return checkIsNetworkTypeAllowed(info.getType(), totalBytes); }
From source file:ch.bfh.instacircle.NetworkActiveActivity.java
/** * Checks whether the current network configuration is how it is supposed to * be/*from w w w . jav a2s .c o m*/ */ public void checkNetworkState() { ConnectivityManager conn = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); SharedPreferences preferences = getSharedPreferences(PREFS_NAME, 0); final String configuredSsid = preferences.getString("SSID", "N/A"); final String password = preferences.getString("password", "N/A"); NetworkInfo nInfo = conn.getNetworkInfo(ConnectivityManager.TYPE_WIFI); String ssid = wifi.getConnectionInfo().getSSID(); Log.d(TAG, "Currently active SSID: " + ssid); // Only check the state if this device is not an access point if (!wifiapmanager.isWifiAPEnabled(wifi)) { Log.d(TAG, "Configured SSID: " + configuredSsid); if (!(nInfo.getDetailedState() == NetworkInfo.DetailedState.CONNECTED && nInfo.getState() == NetworkInfo.State.CONNECTED && ssid.equals(configuredSsid))) { if (repairInitiated == false && repairTime + 6000 < System.currentTimeMillis()) { repairInitiated = true; repairTime = System.currentTimeMillis(); // create a dialog that ask whether you want to repair the // network connection AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle("InstaCircle - Network Connection Lost"); alertDialog.setMessage( "The connection to the network " + configuredSsid + " has been lost. Try to repair?"); alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Repair", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); adhoc.connectToNetwork(configuredSsid, password, NetworkActiveActivity.this, false); repairInitiated = false; } }); alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Leave", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); WifiManager wifiman = (WifiManager) getSystemService(Context.WIFI_SERVICE); new AdhocWifiManager(wifiman).restoreWifiConfiguration(getBaseContext()); new WifiAPManager().disableHotspot(wifiman, getBaseContext()); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.cancelAll(); Intent stopIntent = new Intent(NetworkActiveActivity.this, NetworkService.class); stopService(stopIntent); Intent intent = new Intent(NetworkActiveActivity.this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); } }); alertDialog.show(); } } else { repairInitiated = false; } } }
From source file:fr.univsavoie.ltp.client.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Appliquer le thme LTP a l'ActionBar //setTheme(R.style.Theme_ltp); // Cration de l'activit principale setContentView(R.layout.activity_main); // Instancier les classes utiles setPopup(new Popup(this)); setSession(new Session(this)); setTools(new Tools(this)); // Afficher la ActionBar ActionBar mActionBar = getSupportActionBar(); mActionBar.setHomeButtonEnabled(true); mActionBar.setDisplayShowHomeEnabled(true); // MapView settings map = (MapView) findViewById(R.id.openmapview); map.setTileSource(TileSourceFactory.MAPNIK); map.setBuiltInZoomControls(false);/*from w w w .j av a 2 s . co m*/ map.setMultiTouchControls(true); // MapController settings mapController = map.getController(); //To use MapEventsReceiver methods, we add a MapEventsOverlay: overlay = new MapEventsOverlay(this, this); map.getOverlays().add(overlay); boolean isWifiEnabled = false; boolean isGPSEnabled = false; // Vrifier si le wifi ou le rseau mobile est activ final ConnectivityManager connMgr = (ConnectivityManager) this .getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); final NetworkInfo mobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (wifi.isAvailable() && (wifi.getDetailedState() == DetailedState.CONNECTING || wifi.getDetailedState() == DetailedState.CONNECTED)) { Toast.makeText(this, R.string.toast_wifi, Toast.LENGTH_LONG).show(); isWifiEnabled = true; } else if (mobile.isAvailable() && (mobile.getDetailedState() == DetailedState.CONNECTING || mobile.getDetailedState() == DetailedState.CONNECTED)) { Toast.makeText(this, R.string.toast_3G, Toast.LENGTH_LONG).show(); } else { Toast.makeText(this, R.string.toast_aucun_reseau, Toast.LENGTH_LONG).show(); } // Obtenir le service de localisation locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); // Verifier si le service de localisation GPS est actif, le cas echeant, tester le rseau if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 30 * 1000, 250.0f, this); location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); isGPSEnabled = true; } else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 30 * 1000, 250.0f, this); location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } // Afficher une boite de dialogue et proposer d'activer un ou plusieurs services pas actifs if (!isWifiEnabled || !isGPSEnabled) { //getTools().showSettingsAlert(this, isWifiEnabled, isGPSEnabled); } // Si on a une localisation, on dfinit ses coordonnes geopoint if (location != null) { startPoint = new GeoPoint(location.getLatitude(), location.getLongitude()); } else { // Sinon, on indique des paramtres par dfaut location = getTools().getLastKnownLocation(locationManager); if (location == null) { location = new Location(""); location.setLatitude(46.227638); location.setLongitude(2.213749000000); } startPoint = new GeoPoint(46.227638, 2.213749000000); } setLongitude(location.getLongitude()); setLatitude(location.getLatitude()); destinationPoint = null; viaPoints = new ArrayList<GeoPoint>(); // On recupre quelques paramtres de la session prcdents si possible if (savedInstanceState == null) { mapController.setZoom(15); mapController.setCenter(startPoint); } else { mapController.setZoom(savedInstanceState.getInt("zoom_level")); mapController.setCenter((GeoPoint) savedInstanceState.getParcelable("map_center")); } // Crer un overlay sur la carte pour afficher notre point de dpart myLocationOverlay = new SimpleLocationOverlay(this, new DefaultResourceProxyImpl(this)); map.getOverlays().add(myLocationOverlay); myLocationOverlay.setLocation(startPoint); // Boutton pour zoomer la carte ImageButton btZoomIn = (ImageButton) findViewById(R.id.btZoomIn); btZoomIn.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { map.getController().zoomIn(); } }); // Boutton pour dezoomer la carte ImageButton btZoomOut = (ImageButton) findViewById(R.id.btZoomOut); btZoomOut.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { map.getController().zoomOut(); } }); // Pointeurs d'itinrairea: final ArrayList<ExtendedOverlayItem> waypointsItems = new ArrayList<ExtendedOverlayItem>(); itineraryMarkers = new ItemizedOverlayWithBubble<ExtendedOverlayItem>(this, waypointsItems, map, new ViaPointInfoWindow(R.layout.itinerary_bubble, map)); map.getOverlays().add(itineraryMarkers); //updateUIWithItineraryMarkers(); Button searchButton = (Button) findViewById(R.id.buttonSearch); searchButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { handleSearchLocationButton(); } }); //context menu for clicking on the map is registered on this button. registerForContextMenu(searchButton); // Routes et Itinraires final ArrayList<ExtendedOverlayItem> roadItems = new ArrayList<ExtendedOverlayItem>(); roadNodeMarkers = new ItemizedOverlayWithBubble<ExtendedOverlayItem>(this, roadItems, map); map.getOverlays().add(roadNodeMarkers); if (savedInstanceState != null) { mRoad = savedInstanceState.getParcelable("road"); updateUIWithRoad(mRoad); } //POIs: //POI search interface: String[] poiTags = getResources().getStringArray(R.array.poi_tags); poiTagText = (AutoCompleteTextView) findViewById(R.id.poiTag); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, poiTags); poiTagText.setAdapter(adapter); Button setPOITagButton = (Button) findViewById(R.id.buttonSetPOITag); setPOITagButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //Hide the soft keyboard: InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(poiTagText.getWindowToken(), 0); //Start search: getPOIAsync(poiTagText.getText().toString()); } }); //POI markers: final ArrayList<ExtendedOverlayItem> poiItems = new ArrayList<ExtendedOverlayItem>(); poiMarkers = new ItemizedOverlayWithBubble<ExtendedOverlayItem>(this, poiItems, map, new POIInfoWindow(map)); map.getOverlays().add(poiMarkers); if (savedInstanceState != null) { mPOIs = savedInstanceState.getParcelableArrayList("poi"); updateUIWithPOI(mPOIs); } // Load friends ListView lvListeFriends = (ListView) findViewById(R.id.listViewFriends); //lvListeFriends.setBackgroundResource(R.drawable.listview_roundcorner_item); lvListeFriends.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> adapter, View v, int position, long id) { Friends item = (Friends) adapter.getItemAtPosition(position); if (item.getLongitude() != 0.0 && item.getLatitude() != 0.0) { destinationPoint = new GeoPoint(item.getLongitude(), item.getLatitude()); markerDestination = putMarkerItem(markerDestination, destinationPoint, DEST_INDEX, R.string.destination, R.drawable.marker_destination, -1); getRoadAsync(); map.getController().setCenter(destinationPoint); } else { Toast.makeText(MainActivity.this, R.string.toast_friend_statut, Toast.LENGTH_LONG).show(); } } }); viewMapFilters = (ScrollView) this.findViewById(R.id.scrollViewMapFilters); viewMapFilters.setVisibility(View.GONE); // Initialiser tout ce qui est donnes utilisateur propres l'activit init(); getTools().relocateUser(mapController, map, myLocationOverlay, location); }
From source file:fr.inria.ucn.collectors.NetworkStateCollector.java
/** * /* w w w . j ava 2 s. c om*/ * @param c * @param ts * @param change */ @SuppressWarnings("deprecation") @SuppressLint({ "DefaultLocale", "NewApi" }) public void run(Context c, long ts, boolean change) { try { // current active interface (wifi or mobile) and config ConnectivityManager cm = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE); TelephonyManager tm = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo(); JSONObject data = new JSONObject(); data.put("on_network_state_change", change); // this collection run was triggered by network change data.put("is_connected", (ni != null && ni.isConnectedOrConnecting())); data.put("is_roaming", tm.isNetworkRoaming()); // airplane mode ? if (android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.JELLY_BEAN) { data.put("is_airplane_mode", (Settings.System.getInt(c.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) != 0)); } else { data.put("is_airplane_mode", (Settings.Global.getInt(c.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0)); } if (ni != null) { JSONObject active = new JSONObject(); active.put("type", ni.getType()); active.put("subtype", ni.getSubtype()); active.put("type_name", ni.getTypeName()); active.put("subtype_name", ni.getSubtypeName()); active.put("state", ni.getState().toString()); active.put("detailed_state", ni.getDetailedState().toString()); active.put("is_wifi", (ni.getType() == ConnectivityManager.TYPE_WIFI)); data.put("active_network", active); if (ni.getType() == ConnectivityManager.TYPE_WIFI) { data.put("wifi_network", getWifi(c)); } } // mobile network details data.put("mobile_network", getMobile(tm)); // kernel network statistics data.put("netstat", getNetstat()); // interfaces config Map<String, JSONObject> stats = networkStats(); data.put("ifconfig", getIfconfig(stats)); // double check interfaces data.put("ip_addr_show", getIpAddr(stats)); Helpers.sendResultObj(c, "network_state", ts, data); } catch (JSONException jex) { Log.w(Constants.LOGTAG, "failed to create json object", jex); } }