List of usage examples for android.net ConnectivityManager TYPE_MOBILE
int TYPE_MOBILE
To view the source code for android.net ConnectivityManager TYPE_MOBILE.
Click Source Link
From source file:org.basdroid.common.NetworkUtils.java
/** * Check if there is any connectivity to a mobile network * @param context// ww w .ja v a 2 s . c om * @return */ public static boolean isConnectedMobile(Context context) { NetworkInfo info = getNetworkInfo(context); return (info != null && info.isConnected() && info.getType() == ConnectivityManager.TYPE_MOBILE); }
From source file:at.tugraz.ist.akm.networkInterface.WifiIpAddress.java
public String readLocalIpAddress() { NetworkInfo mobileNetInfo = mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (mWifiManager.isWifiEnabled()) { return readWifiIP4Address(); }/* www. j av a 2s . c om*/ if (AppEnvironment.isRunningOnEmulator() && mobileNetInfo != null && mobileNetInfo.isConnected()) { try { return readIP4AddressOfEmulator(); } catch (SocketException e) { mLog.error("not able to read local ip-address", e); } } else if (isWifiAPEnabled()) { return readIp4ApAddress(); } mLog.error("failed to determine correct ip address"); return null; }
From source file:com.nextgis.maplib.util.NetworkUtil.java
public boolean isNetworkAvailable() { if (mConnectionManager == null) { return false; }/*w ww . j a v a 2 s .c o m*/ NetworkInfo info = mConnectionManager.getActiveNetworkInfo(); if (info == null) //|| !cm.getBackgroundDataSetting() { return false; } int netType = info.getType(); if (netType == ConnectivityManager.TYPE_WIFI) { return info.isConnected(); } else if (netType == ConnectivityManager.TYPE_MOBILE) { // netSubtype == TelephonyManager.NETWORK_TYPE_UMTS if (mTelephonyManager != null && !mTelephonyManager.isNetworkRoaming()) { return info.isConnected(); } } return false; }
From source file:com.cloverstudio.spika.management.ConnectionChangeReceiver.java
@Override public void onReceive(Context context, Intent intent) { final ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo(); NetworkInfo mobNetInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); boolean hasInternetConnection = activeNetInfo != null; if (hasInternetConnection) { mConnectionChangeBroadcast.putExtra(HAS_INTERNET_CONNECTION, true); } else {/* w w w. j a v a2 s . co m*/ mConnectionChangeBroadcast.putExtra(HAS_INTERNET_CONNECTION, false); } LocalBroadcastManager.getInstance(context).sendBroadcast(mConnectionChangeBroadcast); }
From source file:com.mytwitter.Network.NetworkHelper.java
public static boolean connectedToMobileNetwork(ConnectivityManager connectivityManager) { NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo(); boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); if (!isConnected) return false; return (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE); }
From source file:com.frostwire.android.gui.NetworkManager.java
/** * aka -> isInternetUp//from w w w . jav a2 s .c o m */ public boolean isDataUp() { ConnectivityManager connectivityManager = getConnectivityManager(); boolean wifiUp = isNetworkTypeUp(connectivityManager, ConnectivityManager.TYPE_WIFI); boolean mobileUp = isNetworkTypeUp(connectivityManager, ConnectivityManager.TYPE_MOBILE); // boolean logic trick, since sometimes android reports WIFI and MOBILE up at the same time return wifiUp != mobileUp; }
From source file:org.basdroid.common.NetworkUtils.java
/** * Check if the connection is fast//from w w w . ja v a 2s . c om * @param type * @param subType * @return */ public static boolean isConnectionFast(int type, int subType) { if (type == ConnectivityManager.TYPE_WIFI) { return true; } else if (type == ConnectivityManager.TYPE_MOBILE) { switch (subType) { case TelephonyManager.NETWORK_TYPE_1xRTT: return false; // ~ 50-100 kbps case TelephonyManager.NETWORK_TYPE_CDMA: return false; // ~ 14-64 kbps case TelephonyManager.NETWORK_TYPE_EDGE: return false; // ~ 50-100 kbps case TelephonyManager.NETWORK_TYPE_EVDO_0: return true; // ~ 400-1000 kbps case TelephonyManager.NETWORK_TYPE_EVDO_A: return true; // ~ 600-1400 kbps case TelephonyManager.NETWORK_TYPE_GPRS: return false; // ~ 100 kbps case TelephonyManager.NETWORK_TYPE_HSDPA: return true; // ~ 2-14 Mbps case TelephonyManager.NETWORK_TYPE_HSPA: return true; // ~ 700-1700 kbps case TelephonyManager.NETWORK_TYPE_HSUPA: return true; // ~ 1-23 Mbps case TelephonyManager.NETWORK_TYPE_UMTS: return true; // ~ 400-7000 kbps /* * Above API level 7, make sure to set android:targetSdkVersion * to appropriate level to use these */ case TelephonyManager.NETWORK_TYPE_EHRPD: // API level 11 return true; // ~ 1-2 Mbps case TelephonyManager.NETWORK_TYPE_EVDO_B: // API level 9 return true; // ~ 5 Mbps case TelephonyManager.NETWORK_TYPE_HSPAP: // API level 13 return true; // ~ 10-20 Mbps case TelephonyManager.NETWORK_TYPE_IDEN: // API level 8 return false; // ~25 kbps case TelephonyManager.NETWORK_TYPE_LTE: // API level 11 return true; // ~ 10+ Mbps // Unknown case TelephonyManager.NETWORK_TYPE_UNKNOWN: default: return false; } } else { return false; } }
From source file:com.near.chimerarevo.services.NewsService.java
@Override protected void onHandleIntent(Intent i) { ConnectivityManager mConnManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); if (mConnManager != null) { mWifi = mConnManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); mMobile = mConnManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (!isMobileConnected() && !isWiFiConnected()) return; }/*from w w w . j av a 2s .co m*/ if (i.getBooleanExtra("shouldNotCreateNotification", false)) mHandler.post(new DisplayToast(this, getResources().getString(R.string.text_loading))); Request request = new Request.Builder().url(URLUtils.getUrl()).build(); try { Response response = OkHttpUtils.getInstance().newCall(request).execute(); String body = response.body().string().trim(); if (!body.isEmpty()) if (readOfflineFile(body)) { ArrayList<String> mJson = new ArrayList<>(); mJson.add((new JsonParser()).parse(body).toString()); SysUtils.writeOfflineFile(this, mJson, "posts.ser"); Intent update = new Intent(this, PostsListWidgetProvider.class); update.setAction(PostsListWidgetProvider.REFRESH_VIEWS_ACTION); sendBroadcast(update); update = new Intent(this, PostsLRWidgetProvider.class); update.setAction(PostsLRWidgetProvider.REFRESH_VIEWS_ACTION); sendBroadcast(update); if (!i.getBooleanExtra("shouldNotCreateNotification", false)) createNotification(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.rincliu.library.util.RLNetUtil.java
/** * @param context//w w w . j a va 2 s . c o m * @return * @throws Exception */ public static boolean isMobileDataEnable(Context context) throws Exception { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); boolean isMobileDataEnable = false; isMobileDataEnable = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) .isConnectedOrConnecting(); return isMobileDataEnable; }
From source file:com.licubeclub.zionhs.Notices_Parents.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_notices_parents); getSupportActionBar().setDisplayHomeAsUpEnabled(true); listview = (ListView) findViewById(R.id.listView); cManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); mobile = cManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); wifi = cManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); SRL = (SwipeRefreshLayout) findViewById(R.id.swipe_container); SRL.setColorSchemeColors(Color.rgb(231, 76, 60), Color.rgb(46, 204, 113), Color.rgb(41, 128, 185), Color.rgb(241, 196, 15)); SRL.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override// w w w .j a va 2 s . com public void onRefresh() { networkTask(); } }); if (mobile.isConnected() || wifi.isConnected()) { } else { Toast toast = Toast.makeText(getApplicationContext(), getString(R.string.network_connection_warning), Toast.LENGTH_LONG); finish(); } networkTask(); }