List of usage examples for android.net NetworkInfo getTypeName
@Deprecated
public String getTypeName()
From source file:com.codestation.henkakuserver.MainActivity.java
public boolean isConnectedInWifi(boolean wifiOnly) { WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); NetworkInfo networkInfo = ((ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE)) .getActiveNetworkInfo();/*from w w w . ja v a2 s. c om*/ boolean wifiEnabled = networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected() && wifiManager.isWifiEnabled() && networkInfo.getTypeName().equals("WIFI"); if (!wifiOnly && !wifiEnabled) { try { final Method method = wifiManager.getClass().getDeclaredMethod("isWifiApEnabled"); method.setAccessible(true); wifiEnabled = (Boolean) method.invoke(wifiManager); } catch (Exception e) { e.printStackTrace(); } } return wifiEnabled; }
From source file:jieehd.villain.updater.VillainUpdater.java
private boolean haveNetworkConnection() { boolean haveConnectedWifi = false; boolean haveConnectedMobile = false; ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] netInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : netInfo) { if (ni.getTypeName().equalsIgnoreCase("WIFI")) if (ni.isConnected()) haveConnectedWifi = true; if (ni.getTypeName().equalsIgnoreCase("MOBILE")) if (ni.isConnected()) haveConnectedMobile = true; }//from w w w . j a v a 2s .c om if (haveConnectedWifi == false && haveConnectedMobile == false) { Log.d("Network State", "false"); AlertDialog.Builder alert = new AlertDialog.Builder(VillainUpdater.this); alert.setTitle("No Data Connection!"); alert.setMessage( "You have no data connection, click ok to turn on WiFi or Mobile Data in order to check for OTA updates."); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // TODO Auto-generated method stub final Intent intent = new Intent(Intent.ACTION_MAIN, null); intent.addCategory(Intent.CATEGORY_LAUNCHER); final ComponentName cn = new ComponentName("com.android.settings", "com.android.settings.wifi.WifiSettings"); intent.setComponent(cn); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub return; } }); alert.show(); } else { download(); } return haveConnectedWifi || haveConnectedMobile; }
From source file:com.android.profilerapp.network.NetworkFragment.java
private Thread getStatisticThread() { return new Thread(new Runnable() { private Statistics statistics; private long[] myStartBytes; private long[] myBytes; private void initialize() { statistics = new Statistics(); myStartBytes = getTrafficBytes(Integer.toString(myUid)); }/*from www. j a v a 2 s .c o m*/ @Override public void run() { initialize(); while (!Thread.currentThread().isInterrupted()) { myBytes = getTrafficBytes(Integer.toString(myUid)); statistics.sendBytesFromFile = myBytes[0] - myStartBytes[0]; statistics.receiveBytesFromFile = myBytes[1] - myStartBytes[1]; // Gets the bytes from API too, because API read is later than file read, API results may be a little larger. myBytes[0] = TrafficStats.getUidTxBytes(myUid) - myStartBytes[0]; myBytes[1] = TrafficStats.getUidRxBytes(myUid) - myStartBytes[1]; if (statistics.sendBytesFromFile > myBytes[0] || statistics.receiveBytesFromFile > myBytes[1]) { Log.d(TAG, String.format( "Bytes reported not in sync. TrafficStats: %1$d, %2$d, getTrafficBytes: %3$d, %4$d", myBytes[0], myBytes[1], statistics.sendBytesFromFile, statistics.receiveBytesFromFile)); } NetworkInfo networkInfo = myConnectivityManager.getActiveNetworkInfo(); statistics.networkName = networkInfo != null && networkInfo.getSubtype() != TelephonyManager.NETWORK_TYPE_UNKNOWN ? networkInfo.getSubtypeName() : networkInfo.getTypeName(); statistics.radioStatus = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? myConnectivityManager.isDefaultNetworkActive() ? "Radio high power" : "Radio not high power" : "Radio status unknown"; statistics.openConnectionCount = getConnectionCount(Integer.toString(myUid)); postStatistics(statistics); try { Thread.currentThread().sleep(200); } catch (InterruptedException e) { e.printStackTrace(); } } } }); }
From source file:org.microg.gms.gcm.TriggerReceiver.java
@Override public void onReceive(Context context, Intent intent) { boolean force = "android.provider.Telephony.SECRET_CODE".equals(intent.getAction()) || FORCE_TRY_RECONNECT.equals(intent.getAction()); ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (!GcmPrefs.get(context).isEnabled() && !force) { Log.d(TAG, "Ignoring " + intent + ": gcm is disabled"); return;/* w w w . ja v a2s .c o m*/ } if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) { McsService.resetCurrentDelay(); } if (LastCheckinInfo.read(context).androidId == 0) { Log.d(TAG, "Ignoring " + intent + ": need to checkin first."); return; } force |= "android.intent.action.BOOT_COMPLETED".equals(intent.getAction()); NetworkInfo networkInfo = cm.getActiveNetworkInfo(); if (!force) { if (networkInfo == null || !networkInfo.isConnected()) { Log.d(TAG, "Ignoring " + intent + ": network is offline, scheduling new attempt."); McsService.scheduleReconnect(context); return; } else if (!GcmPrefs.get(context).isEnabledFor(networkInfo)) { Log.d(TAG, "Ignoring " + intent + ": gcm is disabled for " + networkInfo.getTypeName()); return; } } if (!McsService.isConnected() || force) { Log.d(TAG, "Not connected to GCM but should be, asking the service to start up. Triggered by: " + intent); startWakefulService(context, new Intent(ACTION_CONNECT, null, context, McsService.class).putExtra(EXTRA_REASON, intent)); } else { if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) { Log.d(TAG, "Ignoring " + intent + ": service is running. schedule reconnect instead."); McsService.scheduleReconnect(context); } else { Log.d(TAG, "Ignoring " + intent + ": service is running. heartbeat instead."); startWakefulService(context, new Intent(ACTION_HEARTBEAT, null, context, McsService.class) .putExtra(EXTRA_REASON, intent)); } } }
From source file:edu.wpi.khufnagle.lighthousenavigator.PhotographsActivity.java
/** * Determines whether the user can connect to the Internet using a Wi-Fi * network or over a cellular network.// w w w.j av a 2s.c om * @return True if the user has either type of Internet connection */ /* * Courtesy of * http://stackoverflow.com/questions/4238921/android-detect-whether * -there-is-an-internet-connection-available */ private boolean networkConnectionExists() { boolean wifiConnectionExists = false; boolean mobileConnectionExists = false; final ConnectivityManager connManager = (ConnectivityManager) this .getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo[] connSources = connManager.getAllNetworkInfo(); for (final NetworkInfo connSource : connSources) { if (connSource.getTypeName().equalsIgnoreCase("WIFI")) { if (connSource.isConnected()) { wifiConnectionExists = true; } } if (connSource.getTypeName().equalsIgnoreCase("MOBILE")) { if (connSource.isConnected()) { mobileConnectionExists = true; } } } return wifiConnectionExists || mobileConnectionExists; }
From source file:com.fine47.http.ActivityHttpClient.java
/** * Checks whether the system is online (connected to a network) or not. * * @return TRUE if the system is online, FALSE otherwise *//*from w w w.j a v a2s .c o m*/ public boolean isOnline() { try { ConnectivityManager cm = (ConnectivityManager) getContext().getApplicationContext() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (null != netInfo) { // Check for availability and if it's really connected. isConnected = netInfo.isAvailable() && netInfo.isConnectedOrConnecting(); // Get available networks' info. NetworkInfo[] netsInfo = cm.getAllNetworkInfo(); // What kind of networks are available. for (NetworkInfo ni : netsInfo) { if (ni.isConnected()) { String niType = ni.getTypeName(); if ("WIFI".equalsIgnoreCase(niType)) { isWifiConnected = true; } else if ("MOBILE".equalsIgnoreCase(niType)) { isMobileConnected = true; } } } } else { isConnected = false; } return isConnected; } catch (Throwable error) { if (isDebugging()) { Log.e(LOG_TAG, "Error while detecting network status.", error); } } return isConnected; }
From source file:com.lemon.lime.MainActivity.java
private boolean isconnected() { boolean haveConnectedWifi = false; boolean haveConnectedMobile = false; ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] netInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : netInfo) { if (ni.getTypeName().equalsIgnoreCase("WIFI")) if (ni.isConnected()) haveConnectedWifi = true; if (ni.getTypeName().equalsIgnoreCase("MOBILE")) if (ni.isConnected()) haveConnectedMobile = true; }/*from w w w . ja v a 2 s. c o m*/ return haveConnectedWifi || haveConnectedMobile; }
From source file:es.farfuteam.vncpp.controller.ActivityTabs.java
/** * @return True if the connectivity type is Wifi, false in another case. * @brief Checks the connectivity type of the terminal * @details Checks the connectivity type of the terminal *//*w ww . j a va 2s . co m*/ //devuelve true si es conexion wifi, false en caso contrario private boolean isWifiConnectivityType() { ConnectivityManager connectivityManager = (ConnectivityManager) this .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = connectivityManager.getActiveNetworkInfo(); String connectionType = info.getTypeName(); if (connectionType.equalsIgnoreCase("wifi")) { return true; } else { //3g u otro tipo return false; } }
From source file:it.sasabz.android.sasabus.fragments.OnlineSearchFragment.java
/** * this method checks if a networkconnection is active or not * @return boolean if the network is reachable or not */// w w w. ja va 2 s .c o m private boolean haveNetworkConnection() { boolean haveConnectedWifi = false; boolean haveConnectedMobile = false; ConnectivityManager cm = (ConnectivityManager) (getActivity() .getSystemService(Context.CONNECTIVITY_SERVICE)); NetworkInfo[] netInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : netInfo) { //testing WIFI connection if (ni.getTypeName().equalsIgnoreCase("WIFI")) if (ni.isConnected()) haveConnectedWifi = true; //testing GPRS/EDGE/UMTS/HDSPA/HUSPA/LTE connection if (ni.getTypeName().equalsIgnoreCase("MOBILE")) if (ni.isConnected()) haveConnectedMobile = true; } return haveConnectedWifi || haveConnectedMobile; }
From source file:com.android.settings.cyanogenmod.LtoService.java
private boolean shouldDownload() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); NetworkInfo info = cm.getActiveNetworkInfo(); if (info == null || !info.isConnected()) { if (ALOGV) Log.v(TAG, "No network connection is available for LTO download"); } else {//from w w w . j av a 2 s . c om boolean wifiOnly = prefs.getBoolean(LocationSettings.KEY_GPS_DOWNLOAD_DATA_WIFI_ONLY, true); if (wifiOnly && info.getType() != ConnectivityManager.TYPE_WIFI) { if (ALOGV) { Log.v(TAG, "Active network is of type " + info.getTypeName() + ", but Wifi only was selected"); } return false; } } long now = System.currentTimeMillis(); long lastDownload = getLastDownload(); long due = lastDownload + LongTermOrbits.getDownloadInterval(); if (ALOGV) { Log.v(TAG, "Now " + now + " due " + due + "(" + new Date(due) + ")"); } if (lastDownload != 0 && now < due) { if (ALOGV) Log.v(TAG, "LTO download is not due yet"); return false; } return true; }