List of usage examples for android.net NetworkInfo toString
@Override
public String toString()
From source file:Main.java
public static String getNetworkInfo(Context act) { ConnectivityManager cm = (ConnectivityManager) act.getSystemService(Context.CONNECTIVITY_SERVICE); if (cm == null) return null; NetworkInfo info = cm.getActiveNetworkInfo(); if (info != null) return info.toString(); return null;/*from w w w. j a v a2s . c om*/ }
From source file:com.DGSD.DGUtils.Http.BetterHttp.java
public static void updateProxySettings() { if (appContext == null) { return;//from ww w . j a v a 2 s . c o m } HttpParams httpParams = httpClient.getParams(); ConnectivityManager connectivity = (ConnectivityManager) appContext .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo nwInfo = connectivity.getActiveNetworkInfo(); if (nwInfo == null) { return; } Log.i(LOG_TAG, nwInfo.toString()); if (nwInfo.getType() == ConnectivityManager.TYPE_MOBILE) { String proxyHost = Proxy.getHost(appContext); if (proxyHost == null) { proxyHost = Proxy.getDefaultHost(); } int proxyPort = Proxy.getPort(appContext); if (proxyPort == -1) { proxyPort = Proxy.getDefaultPort(); } if (proxyHost != null && proxyPort > -1) { HttpHost proxy = new HttpHost(proxyHost, proxyPort); httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } else { httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null); } } else { httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null); } }
From source file:com.adam.aslfms.util.Util.java
public static NetworkStatus checkForOkNetwork(Context ctx) { AppSettings settings = new AppSettings(ctx); PowerOptions powerOptions = checkPower(ctx); NetworkOptions networkOptions = settings.getNetworkOptions(powerOptions); boolean roaming = settings.getSubmitOnRoaming(powerOptions); ConnectivityManager connectivityManager = (ConnectivityManager) ctx .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = connectivityManager.getActiveNetworkInfo(); if (netInfo == null) { Log.d(TAG, "netInfo == null"); }/*from w w w . j av a 2 s . c o m*/ if (netInfo != null) { Log.d(TAG, "conn: " + netInfo.isConnected() + " : " + netInfo.toString()); } if (netInfo == null || !netInfo.isConnected()) { return NetworkStatus.DISCONNECTED; } if (netInfo.isRoaming() && !roaming) { return NetworkStatus.UNFIT; } int netType = netInfo.getType(); int netSubType = netInfo.getSubtype(); Log.d(TAG, "netType: " + netType); Log.d(TAG, "netSubType: " + netSubType); if (networkOptions.isNetworkTypeForbidden(netType)) { Log.d(TAG, "Network type forbidden"); return NetworkStatus.UNFIT; } if (networkOptions.isNetworkSubTypeForbidden(netType, netSubType)) { Log.d(TAG, "Network sub type forbidden"); return NetworkStatus.UNFIT; } return NetworkStatus.OK; }
From source file:com.github.ignition.support.http.IgnitedHttpClient.java
public void updateProxySettings() { if (appContext == null) { return;/*from ww w .jav a2 s .c o m*/ } HttpParams httpParams = httpClient.getParams(); ConnectivityManager connectivity = (ConnectivityManager) appContext .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo nwInfo = connectivity.getActiveNetworkInfo(); if (nwInfo == null) { return; } Log.i(LOG_TAG, nwInfo.toString()); if (nwInfo.getType() == ConnectivityManager.TYPE_MOBILE) { String proxyHost = Proxy.getHost(appContext); if (proxyHost == null) { proxyHost = Proxy.getDefaultHost(); } int proxyPort = Proxy.getPort(appContext); if (proxyPort == -1) { proxyPort = Proxy.getDefaultPort(); } if (proxyHost != null && proxyPort > -1) { HttpHost proxy = new HttpHost(proxyHost, proxyPort); httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } else { httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null); } } else { httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null); } }
From source file:cn.edu.szjm.support.http.IgnitedHttp.java
/** * Updates the underlying HTTP client's proxy settings with what the user has entered in the APN * settings. This will be called automatically if {@link #listenForConnectivityChanges(Context)} * has been called. <b>This requires the {@link Manifest.permission#ACCESS_NETWORK_STATE} * permission</b>.// www . j ava 2 s .c o m * * @param context * the current context */ public void updateProxySettings(Context context) { if (context == null) { return; } HttpParams httpParams = httpClient.getParams(); ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo nwInfo = connectivity.getActiveNetworkInfo(); if (nwInfo == null) { return; } Log.i(LOG_TAG, nwInfo.toString()); if (nwInfo.getType() == ConnectivityManager.TYPE_MOBILE) { String proxyHost = Proxy.getHost(context); if (proxyHost == null) { proxyHost = Proxy.getDefaultHost(); } int proxyPort = Proxy.getPort(context); if (proxyPort == -1) { proxyPort = Proxy.getDefaultPort(); } if (proxyHost != null && proxyPort > -1) { HttpHost proxy = new HttpHost(proxyHost, proxyPort); httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } else { httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null); } } else { httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null); } }
From source file:org.openbmap.soapclient.CheckServerTask.java
/** * Gives system some time to initialize network adapter and connections *//*from ww w . j a va 2 s . c om*/ private void waitForConnect() { final ConnectivityManager cm = (ConnectivityManager) mContext .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = null; // wait for state change for (int i = 0; i < WAIT_FOR_CONNECTING; i++) { try { networkInfo = cm.getActiveNetworkInfo(); if ((networkInfo != null) && (networkInfo.getState() == State.CONNECTING || networkInfo.getState() == State.CONNECTED)) { break; } Log.i(TAG, "Network neither connected nor connecting. Wait 1 sec.."); Thread.sleep(1000); } catch (final InterruptedException e) { // ignore } } networkInfo = cm.getActiveNetworkInfo(); if (networkInfo != null) { Log.i(TAG, "Connection status" + networkInfo.toString()); } // once we're in CONNECTING state, wait another couple of seconds if (networkInfo != null && networkInfo.getState().equals(State.CONNECTING)) { // if in connecting state, wait 1 second for connection // this process is repeated multiple times according to retries Log.i(TAG, "Hoorray: after all connecting.. Wait for connection ready"); for (int i = 0; i < WAIT_FOR_CONNECTED; i++) { if (isOnline()) { return; } Log.i(TAG, "Connection not yet ready. Waiting 1 sec.."); try { Thread.sleep(1000); } catch (final InterruptedException e) { // ignore } } } networkInfo = cm.getActiveNetworkInfo(); if (networkInfo != null) { Log.i(TAG, "Waited enough: now " + networkInfo.toString()); } }
From source file:cx.ring.service.LocalService.java
private void updateConnectivityState() { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); Log.w(TAG, "ActiveNetworkInfo (Wifi): " + (ni == null ? "null" : ni.toString())); isWifiConn = ni != null && ni.isConnected(); ni = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); Log.w(TAG, "ActiveNetworkInfo (mobile): " + (ni == null ? "null" : ni.toString())); isMobileConn = ni != null && ni.isConnected(); try {/*from w w w . j av a 2s.c o m*/ getRemoteService().setAccountsActive(isConnected()); } catch (RemoteException e) { e.printStackTrace(); } // if account list loaded if (!ip2ip_account.isEmpty()) sendBroadcast(new Intent(ACTION_ACCOUNT_UPDATE)); }