List of usage examples for android.telephony TelephonyManager NETWORK_TYPE_UNKNOWN
int NETWORK_TYPE_UNKNOWN
To view the source code for android.telephony TelephonyManager NETWORK_TYPE_UNKNOWN.
Click Source Link
From source file:Main.java
private static String mobileNetworkType(Context context) { TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (telephonyManager == null) { return "TM==null"; }/*w w w . j av a2 s . com*/ switch (telephonyManager.getNetworkType()) { case TelephonyManager.NETWORK_TYPE_1xRTT:// ~ 50-100 kbps return "2G"; case TelephonyManager.NETWORK_TYPE_CDMA:// ~ 14-64 kbps return "2G"; case TelephonyManager.NETWORK_TYPE_EDGE:// ~ 50-100 kbps return "2G"; case TelephonyManager.NETWORK_TYPE_EVDO_0:// ~ 400-1000 kbps return "3G"; case TelephonyManager.NETWORK_TYPE_EVDO_A:// ~ 600-1400 kbps return "3G"; case TelephonyManager.NETWORK_TYPE_GPRS:// ~ 100 kbps return "2G"; case TelephonyManager.NETWORK_TYPE_HSDPA:// ~ 2-14 Mbps return "3G"; case TelephonyManager.NETWORK_TYPE_HSPA:// ~ 700-1700 kbps return "3G"; case TelephonyManager.NETWORK_TYPE_HSUPA: // ~ 1-23 Mbps return "3G"; case TelephonyManager.NETWORK_TYPE_UMTS:// ~ 400-7000 kbps return "3G"; case TelephonyManager.NETWORK_TYPE_EHRPD:// ~ 1-2 Mbps return "3G"; case TelephonyManager.NETWORK_TYPE_EVDO_B: // ~ 5 Mbps return "3G"; case TelephonyManager.NETWORK_TYPE_HSPAP:// ~ 10-20 Mbps return "3G"; case TelephonyManager.NETWORK_TYPE_IDEN:// ~25 kbps return "2G"; case TelephonyManager.NETWORK_TYPE_LTE:// ~ 10+ Mbps return "4G"; case TelephonyManager.NETWORK_TYPE_UNKNOWN: return "UNKNOWN"; default: return "4G"; } }
From source file:Main.java
/** * Check if the connection is fast//ww w .ja v a2 s . c o m * * @param type * @param subType * @return */ // Courtsey: https://gist.github.com/emil2k/5130324 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:Main.java
/** * Whether is fast mobile network//from w w w . j a v a 2 s .c om */ private static boolean isFastMobileNetwork(Context context) { TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (telephonyManager == null) { return false; } switch (telephonyManager.getNetworkType()) { case TelephonyManager.NETWORK_TYPE_1xRTT: return false; case TelephonyManager.NETWORK_TYPE_CDMA: return false; case TelephonyManager.NETWORK_TYPE_EDGE: return false; case TelephonyManager.NETWORK_TYPE_EVDO_0: return true; case TelephonyManager.NETWORK_TYPE_EVDO_A: return true; case TelephonyManager.NETWORK_TYPE_GPRS: return false; case TelephonyManager.NETWORK_TYPE_HSDPA: return true; case TelephonyManager.NETWORK_TYPE_HSPA: return true; case TelephonyManager.NETWORK_TYPE_HSUPA: return true; case TelephonyManager.NETWORK_TYPE_UMTS: return true; case TelephonyManager.NETWORK_TYPE_EHRPD: return true; case TelephonyManager.NETWORK_TYPE_EVDO_B: return true; case TelephonyManager.NETWORK_TYPE_HSPAP: return true; case TelephonyManager.NETWORK_TYPE_IDEN: return false; case TelephonyManager.NETWORK_TYPE_LTE: return true; case TelephonyManager.NETWORK_TYPE_UNKNOWN: return false; default: return false; } }
From source file:Main.java
private 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_GPRS: return false; // ~ 100 kbps case TelephonyManager.NETWORK_TYPE_EVDO_0: return false; // ~25 kbps case TelephonyManager.NETWORK_TYPE_LTE: return true; // ~ 400-1000 kbps case TelephonyManager.NETWORK_TYPE_EVDO_A: return true; // ~ 600-1400 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 case TelephonyManager.NETWORK_TYPE_EHRPD: return true; // ~ 1-2 Mbps case TelephonyManager.NETWORK_TYPE_EVDO_B: return true; // ~ 5 Mbps case TelephonyManager.NETWORK_TYPE_HSPAP: return true; // ~ 10-20 Mbps case TelephonyManager.NETWORK_TYPE_IDEN: return true; // ~ 10+ Mbps case TelephonyManager.NETWORK_TYPE_UNKNOWN: default:// ww w .ja va 2s.com return false; } } else { return false; } }
From source file:Main.java
/** * Whether is fast mobile network/* ww w .j a v a2 s.co m*/ * * @param context * @return */ private static boolean isFastMobileNetwork(Context context) { TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (telephonyManager == null) { return false; } switch (telephonyManager.getNetworkType()) { case TelephonyManager.NETWORK_TYPE_1xRTT: return false; case TelephonyManager.NETWORK_TYPE_CDMA: return false; case TelephonyManager.NETWORK_TYPE_EDGE: return false; case TelephonyManager.NETWORK_TYPE_EVDO_0: return true; case TelephonyManager.NETWORK_TYPE_EVDO_A: return true; case TelephonyManager.NETWORK_TYPE_GPRS: return false; case TelephonyManager.NETWORK_TYPE_HSDPA: return true; case TelephonyManager.NETWORK_TYPE_HSPA: return true; case TelephonyManager.NETWORK_TYPE_HSUPA: return true; case TelephonyManager.NETWORK_TYPE_UMTS: return true; case TelephonyManager.NETWORK_TYPE_EHRPD: return true; case TelephonyManager.NETWORK_TYPE_EVDO_B: return true; case TelephonyManager.NETWORK_TYPE_HSPAP: return true; case TelephonyManager.NETWORK_TYPE_IDEN: return false; case TelephonyManager.NETWORK_TYPE_LTE: return true; case TelephonyManager.NETWORK_TYPE_UNKNOWN: return false; default: return false; } }
From source file:com.nearnotes.NoteLocation.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Use the Builder class for convenient dialog construction Bundle extras = getArguments();// w w w.j av a2s . co m mTypeFrag = extras.getInt("TypeFrag"); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity()); Boolean gpsPref = sharedPref.getBoolean("pref_key_ignore_gps", false); mLocationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); mCriteria = new Criteria(); if (gpsPref) { mCriteria.setPowerRequirement(Criteria.POWER_HIGH); } else mCriteria.setPowerRequirement(Criteria.POWER_MEDIUM); mProvider = mLocationManager.getBestProvider(mCriteria, true); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); boolean oldApi = false; int locationMode = 4; Log.e("mProvider", mProvider); ConnectivityManager cm = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); boolean networkAvailable = true; TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE); boolean networkType = true; if (tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_UNKNOWN && !networkInfo.isConnected()) { networkType = false; } Log.d("Phone state before if statement", "Phone State: " + mServiceState); Log.e("network isavailable", String.valueOf(networkInfo.isAvailable())); if (!networkType || !mLocationManager.isProviderEnabled("network")) { networkAvailable = false; } try { Log.e("Location_mode", String.valueOf( Settings.Secure.getInt(getActivity().getContentResolver(), Settings.Secure.LOCATION_MODE))); locationMode = Settings.Secure.getInt(getActivity().getContentResolver(), Settings.Secure.LOCATION_MODE); } catch (SettingNotFoundException e) { oldApi = true; // TODO Auto-generated catch block e.printStackTrace(); } if ((oldApi && mProvider.matches("passive")) || locationMode == LOCATION_MODE_OFF || (!networkAvailable && (mProvider.matches("network") || (!gpsPref && mProvider.matches("gps"))))) { builder.setTitle(getString(R.string.dialog_location_no_location_services_title)); builder.setMessage(getString(R.string.dialog_location_no_location_services_message)); builder.setNeutralButton(R.string.dialog_location_button_settings, noNetworkButton); mAbortRequest = true; } else if ((oldApi && mProvider.matches("gps") && gpsPref) || (mProvider.matches("gps") && gpsPref && (locationMode == LOCATION_MODE_SENSORS_ONLY || locationMode == LOCATION_MODE_HIGH_ACCURACY))) { if (mTypeFrag == NOTE_EDIT) { builder.setTitle(getString(R.string.dialog_location_finding_note_gps)); } else if (mTypeFrag == NOTE_LIST) { builder.setTitle(getString(R.string.dialog_location_updating_note_gps)); } if (locationMode == LOCATION_MODE_SENSORS_ONLY || (oldApi && mProvider.matches("gps")) || !networkAvailable) { builder.setMessage(getString(R.string.dialog_location_only_gps_message)); builder.setNeutralButton(R.string.dialog_location_button_settings, noNetworkButton); } else builder.setPositiveButton(R.string.dialog_location_use_network, null); builder.setView(getActivity().getLayoutInflater().inflate(R.layout.dialogue_location, null)); } else if ((oldApi && mProvider.matches("network")) || (mProvider.matches("network") && (locationMode == LOCATION_MODE_BATTERY_SAVING || locationMode == LOCATION_MODE_HIGH_ACCURACY))) { builder.setView(getActivity().getLayoutInflater().inflate(R.layout.dialogue_location, null)); if (mTypeFrag == NOTE_EDIT) { builder.setTitle(getString(R.string.dialog_location_finding_note_network)); } else if (mTypeFrag == NOTE_LIST) { builder.setTitle(getString(R.string.dialog_location_updating_note_network)); } } builder.setNegativeButton(R.string.cancel, cancelListener); // Create the AlertDialog object and return it // builder.create(); builder.setOnKeyListener(new DialogInterface.OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { mCallback.onLocationFound(null, mTypeFrag); mLocationManager.removeUpdates(NoteLocation.this); Toast.makeText(getActivity(), "Location request cancelled", Toast.LENGTH_SHORT).show(); dialog.cancel(); return true; } return false; } }); mRealDialog = builder.create(); // final LocationListener getFragment() = this.; mRealDialog.setOnShowListener(usingNetwork); mRealDialog.setCanceledOnTouchOutside(false); // mRealDialog.setCancelable(false); return mRealDialog; }
From source file:org.basdroid.common.NetworkUtils.java
/** * Check if the connection is fast/*from w w w . j a v a2 s.c o m*/ * @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.example.testapplication.DialogLocation.java
@SuppressLint("InlinedApi") @Override/*from w ww .ja v a 2s .c o m*/ public Dialog onCreateDialog(Bundle savedInstanceState) { mProgressBar = new ProgressBar(getActivity(), null, android.R.attr.progressBarStyleLarge); mProgressBarInv = new ProgressBar(getActivity(), null, android.R.attr.progressBarStyleLarge); mProgressBarInv.setVisibility(ProgressBar.GONE); mLocationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); mCriteria = new Criteria(); int criteria = (mGpsPref) ? Criteria.POWER_HIGH : Criteria.POWER_MEDIUM; mCriteria.setPowerRequirement(criteria); mProvider = mLocationManager.getBestProvider(mCriteria, true); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); ConnectivityManager cm = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE); int telephonyInfo = tm.getNetworkType(); boolean networkAvailable = true; if ((telephonyInfo == TelephonyManager.NETWORK_TYPE_UNKNOWN && !networkInfo.isConnected()) || !mLocationManager.isProviderEnabled("network")) { networkAvailable = false; } int locationMode = -1; int locationType = -1; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { try { locationMode = Settings.Secure.getInt(getActivity().getContentResolver(), Settings.Secure.LOCATION_MODE); } catch (SettingNotFoundException e) { e.printStackTrace(); } if (locationMode == Settings.Secure.LOCATION_MODE_OFF || (!networkAvailable && (mProvider.matches("network")))) locationType = NO_LOCATION_SERVICES; else if (mGpsPref && (locationMode == Settings.Secure.LOCATION_MODE_SENSORS_ONLY || locationMode == Settings.Secure.LOCATION_MODE_HIGH_ACCURACY)) locationType = (locationMode == Settings.Secure.LOCATION_MODE_SENSORS_ONLY || !networkAvailable) ? USING_ONLY_GPS_LOCATION : USING_GPS_LOCATION_NETWORK_AVAILABLE; else if (mProvider.matches("network") && (locationMode == Settings.Secure.LOCATION_MODE_BATTERY_SAVING || locationMode == Settings.Secure.LOCATION_MODE_HIGH_ACCURACY)) locationType = USING_NETWORK_LOCATION; } else { if (mProvider.matches("passive") || !networkAvailable && (mProvider.matches("network") || (!mGpsPref && mProvider.matches("gps")))) locationType = NO_LOCATION_SERVICES; else if (mProvider.matches("gps") && mGpsPref) locationType = ((mProvider.matches("gps")) || !networkAvailable) ? USING_ONLY_GPS_LOCATION : USING_GPS_LOCATION_NETWORK_AVAILABLE; else if (mProvider.matches("network")) locationType = USING_NETWORK_LOCATION; } switch (locationType) { case NO_LOCATION_SERVICES: builder.setTitle(DIALOG_LOCATION_NO_LOCATION_SERVICES_TITLE); builder.setMessage(DIALOG_LOCATION_NO_LOCATION_SERVICES_MESSAGE); builder.setNeutralButton(DIALOG_LOCATION_BUTTON_SETTINGS, noNetworkButton); mAbortRequest = true; break; case USING_ONLY_GPS_LOCATION: builder.setTitle(DIALOG_LOCATION_UPDATING_GPS_TITLE); builder.setMessage(DIALOG_LOCATION_ONLY_GPS_MESSAGE); builder.setNeutralButton(DIALOG_LOCATION_BUTTON_SETTINGS, noNetworkButton); builder.setView(mProgressBar); break; case USING_GPS_LOCATION_NETWORK_AVAILABLE: builder.setTitle(DIALOG_LOCATION_UPDATING_GPS_TITLE); builder.setPositiveButton(DIALOG_LOCATION_USE_NETWORK, null); builder.setView(mProgressBar); break; case USING_NETWORK_LOCATION: builder.setView(mProgressBar); builder.setTitle(DIALOG_LOCATION_UPDATING_NETWORK_TITLE); break; } builder.setNegativeButton(DIALOG_LOCATION_CANCEL, cancelListener); builder.setOnKeyListener(new DialogInterface.OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { mCallback.onLocationFound(null, mFragmentId); mLocationManager.removeUpdates(DialogLocation.this); Toast.makeText(getActivity(), "Location request cancelled", Toast.LENGTH_SHORT).show(); dialog.cancel(); return true; } return false; } }); mRealDialog = builder.create(); mRealDialog.setOnShowListener(usingNetwork); mRealDialog.setCanceledOnTouchOutside(false); return mRealDialog; }
From source file:hobby.wei.c.phone.Network.java
private static Type getType(NetworkInfo netInfo) { Type type;/*from w w w . j a va 2 s . co m*/ //?TYPE_WIFI?TYPE_MOBILE?TYPE_MOBILE_MMS if (netInfo.getType() == ConnectivityManager.TYPE_WIFI) { //wifi? type = Type.WIFI; } else { //TYPE_WIFI switch (netInfo.getSubtype()) { case TelephonyManager.NETWORK_TYPE_UNKNOWN: type = Type.NO_NET; break; case TelephonyManager.NETWORK_TYPE_GPRS: case TelephonyManager.NETWORK_TYPE_EDGE: type = Type.G2; break; case TelephonyManager.NETWORK_TYPE_UMTS: case TelephonyManager.NETWORK_TYPE_CDMA: //3G case TelephonyManager.NETWORK_TYPE_EVDO_0: case TelephonyManager.NETWORK_TYPE_EVDO_A: case TelephonyManager.NETWORK_TYPE_1xRTT: //2.5GCDMA case TelephonyManager.NETWORK_TYPE_HSDPA: case TelephonyManager.NETWORK_TYPE_HSUPA: case TelephonyManager.NETWORK_TYPE_HSPA: case TelephonyManager.NETWORK_TYPE_IDEN: case TelephonyManager.NETWORK_TYPE_EVDO_B: case TelephonyManager.NETWORK_TYPE_EHRPD: case TelephonyManager.NETWORK_TYPE_HSPAP: type = Type.G3; break; case TelephonyManager.NETWORK_TYPE_LTE: type = Type.G4; break; default: type = Type.G4; break; } } return type; }
From source file:android_network.hetnet.vpn_service.Util.java
public static int getNetworkType(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = (cm == null ? null : cm.getActiveNetworkInfo()); return (ni == null ? TelephonyManager.NETWORK_TYPE_UNKNOWN : ni.getSubtype()); }