本文整理汇总了Java中android.net.ConnectivityManager.TYPE_MOBILE属性的典型用法代码示例。如果您正苦于以下问题:Java ConnectivityManager.TYPE_MOBILE属性的具体用法?Java ConnectivityManager.TYPE_MOBILE怎么用?Java ConnectivityManager.TYPE_MOBILE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.net.ConnectivityManager
的用法示例。
在下文中一共展示了ConnectivityManager.TYPE_MOBILE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onReceive
@Override
public void onReceive(Context context, Intent intent) {
if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
ConnectivityManager manager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
mContext = context;
NetworkInfo activeNetwork = manager.getActiveNetworkInfo();
if (activeNetwork != null) { // connected to the internet
if (activeNetwork.isConnected()) {
//在网络类型变化时,如4G切换到wifi,不同wifi间切换等,需要重新执行HttpDNS请求刷新本地缓存
if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) {
Log.i(TAG, "连接到WiFi");
new Thread(updateCache).start();
} else if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) {
Log.i(TAG, "链接到移动网络");
new Thread(updateCache).start();
}
} else {
Log.e(TAG, "当前没有网络连接,请确保你已经打开网络 ");
}
} else {
Log.e(TAG, "当前没有网络连接,请确保你已经打开网络 ");
}
}
}
示例2: keyForNetwork
/**
* Get the preference <b>partial</b> key for a given network kind
*
* @param networkType Type of the network {@link ConnectivityManager}
* @param subType Subtype of the network {@link TelephonyManager}
* @return The partial key for the network kind
*/
private static String keyForNetwork(int networkType, int subType) {
if (networkType == ConnectivityManager.TYPE_WIFI) {
return "wifi";
} else if (networkType == ConnectivityManager.TYPE_MOBILE) {
// 3G (or better)
if (subType >= TelephonyManager.NETWORK_TYPE_UMTS) {
return "3g";
}
// GPRS (or unknown)
if (subType == TelephonyManager.NETWORK_TYPE_GPRS
|| subType == TelephonyManager.NETWORK_TYPE_UNKNOWN) {
return "gprs";
}
// EDGE
if (subType == TelephonyManager.NETWORK_TYPE_EDGE) {
return "edge";
}
}
return "other";
}
示例3: getNetworkType
/**
* 获取当前网络类型
*
* @return 0:没有网络 1:WIFI网络 2:WAP网络 3:NET网络
*/
public static int getNetworkType(Context context) {
int netType = 0;
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
if (networkInfo == null) {
return netType;
}
int nType = networkInfo.getType();
if (nType == ConnectivityManager.TYPE_MOBILE) {
String extraInfo = networkInfo.getExtraInfo();
if (extraInfo != null && !extraInfo.isEmpty()) {
if (extraInfo.toLowerCase().equals("cmnet")) {
netType = NETTYPE_CMNET;
} else {
netType = NETTYPE_CMWAP;
}
}
} else if (nType == ConnectivityManager.TYPE_WIFI) {
netType = NETTYPE_WIFI;
}
return netType;
}
示例4: getNetworkType
/**
* 获取当前网络类型
*
* @return 0:没有网络 1:WIFI网络 2:WAP网络 3:NET网络
*/
public static int getNetworkType(Context context) {
int netType = 0;
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
if (networkInfo == null) {
return netType;
}
int nType = networkInfo.getType();
if (nType == ConnectivityManager.TYPE_MOBILE) {
String extraInfo = networkInfo.getExtraInfo();
if (extraInfo != null && !extraInfo.isEmpty()) {
if (extraInfo.equalsIgnoreCase("cmnet")) {
netType = NETTYPE_CMNET;
} else {
netType = NETTYPE_CMWAP;
}
}
} else if (nType == ConnectivityManager.TYPE_WIFI) {
netType = NETTYPE_WIFI;
}
return netType;
}
示例5: getNetworkType
/**
* 获取当前网络类型
*
* @return 0:没有网络 1:WIFI网络 2:WAP网络 3:NET网络
*/
public static int getNetworkType(Context context) {
int netType = NetworkUtils.NET_TYPE_NOT;
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
if (networkInfo == null) {
return netType;
}
int networkInfoType = networkInfo.getType();
if (networkInfoType == ConnectivityManager.TYPE_MOBILE) {
String extraInfo = networkInfo.getExtraInfo();
if (!StringUtils.isEmpty(extraInfo)) {
if (extraInfo.toLowerCase(Locale.getDefault()).equals("cmnet")) {
netType = NetworkUtils.NET_TYPE_CM_NET;
} else {
netType = NetworkUtils.NET_TYPE_CM_WAP;
}
}
} else if (networkInfoType == ConnectivityManager.TYPE_WIFI) {
netType = NetworkUtils.NET_TYPE_WIFI;
}
return netType;
}
示例6: isWifiOpen
/**
* wifi是否开启
*
* @param context
* @return
*/
public static boolean isWifiOpen(Context context) {
boolean isWifiConnect = false;
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
// check the networkInfos numbers
NetworkInfo[] networkInfos = cm.getAllNetworkInfo();
for (int i = 0; i < networkInfos.length; i++) {
if (networkInfos[i].getState() == NetworkInfo.State.CONNECTED) {
if (networkInfos[i].getType() == ConnectivityManager.TYPE_MOBILE) {
isWifiConnect = false;
}
if (networkInfos[i].getType() == ConnectivityManager.TYPE_WIFI) {
isWifiConnect = true;
}
}
}
return isWifiConnect;
}
示例7: getNetworkType
/**
* GPRS 2G(2.5) General Packet Radia Service 114kbps
* EDGE 2G(2.75G) Enhanced Data Rate for GSM Evolution 384kbps
* UMTS 3G WCDMA 联通3G Universal Mobile Telecommunication System 完整的3G移动通信技术标准
* CDMA 2G 电信 Code Division Multiple Access 码分多址
* EVDO_0 3G (EVDO 全程 CDMA2000 1xEV-DO) Evolution - Data Only (Data Optimized) 153.6kps - 2.4mbps 属于3G
* EVDO_A 3G 1.8mbps - 3.1mbps 属于3G过渡,3.5G
* 1xRTT 2G CDMA2000 1xRTT (RTT - 无线电传输技术) 144kbps 2G的过渡,
* HSDPA 3.5G 高速下行分组接入 3.5G WCDMA High Speed Downlink Packet Access 14.4mbps
* HSUPA 3.5G High Speed Uplink Packet Access 高速上行链路分组接入 1.4 - 5.8 mbps
* HSPA 3G (分HSDPA,HSUPA) High Speed Packet Access
* IDEN 2G Integrated Dispatch Enhanced Networks 集成数字增强型网络 (属于2G,来自维基百科)
* EVDO_B 3G EV-DO Rev.B 14.7Mbps 下行 3.5G
* LTE 4G Long Term Evolution FDD-LTE 和 TDD-LTE , 3G过渡,升级版 LTE Advanced 才是4G
* EHRPD 3G CDMA2000向LTE 4G的中间产物 Evolved High Rate Packet Data HRPD的升级
* HSPAP 3G HSPAP 比 HSDPA 快些
*
* @return {@link NetWorkType}
*/
public static NetWorkType getNetworkType(Context context) {
int type = getConnectedTypeINT(context);
switch (type) {
case ConnectivityManager.TYPE_WIFI:
return NetWorkType.Wifi;
case ConnectivityManager.TYPE_MOBILE:
case ConnectivityManager.TYPE_MOBILE_DUN:
case ConnectivityManager.TYPE_MOBILE_HIPRI:
case ConnectivityManager.TYPE_MOBILE_MMS:
case ConnectivityManager.TYPE_MOBILE_SUPL:
int teleType = getTelephonyManager(context).getNetworkType();
switch (teleType) {
case TelephonyManager.NETWORK_TYPE_GPRS:
case TelephonyManager.NETWORK_TYPE_EDGE:
case TelephonyManager.NETWORK_TYPE_CDMA:
case TelephonyManager.NETWORK_TYPE_1xRTT:
case TelephonyManager.NETWORK_TYPE_IDEN:
return NetWorkType.Net2G;
case TelephonyManager.NETWORK_TYPE_UMTS:
case TelephonyManager.NETWORK_TYPE_EVDO_0:
case TelephonyManager.NETWORK_TYPE_EVDO_A:
case TelephonyManager.NETWORK_TYPE_HSDPA:
case TelephonyManager.NETWORK_TYPE_HSUPA:
case TelephonyManager.NETWORK_TYPE_HSPA:
case TelephonyManager.NETWORK_TYPE_EVDO_B:
case TelephonyManager.NETWORK_TYPE_EHRPD:
case TelephonyManager.NETWORK_TYPE_HSPAP:
return NetWorkType.Net3G;
case TelephonyManager.NETWORK_TYPE_LTE:
return NetWorkType.Net4G;
default:
return NetWorkType.UnKnown;
}
default:
return NetWorkType.UnKnown;
}
}
示例8: getConnectedType
public static NetType getConnectedType(Context context) {
NetworkInfo net = getConnectivityManager(context).getActiveNetworkInfo();
if (net != null) {
switch (net.getType()) {
case ConnectivityManager.TYPE_WIFI:
return NetType.Wifi;
case ConnectivityManager.TYPE_MOBILE:
return NetType.Mobile;
default:
return NetType.Other;
}
}
return NetType.None;
}
示例9: isMobile
/**
* 检查是否是移动网络
*/
public static boolean isMobile(Context context) {
NetworkInfo info = getNetworkInfo(context);
if (info != null) {
if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
return true;
}
}
return false;
}
示例10: isConnected
public boolean isConnected(NetworkInfo networkInfo) {
if (null != networkInfo) {
if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
return true;
} else if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
return true;
}
}
return false;
}
示例11: getNetworkType
/**
* 获取当前网络类型
* <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>}</p>
*
* @return 网络类型
* <ul>
* <li>{@link NetworkType#NETWORK_WIFI } </li>
* <li>{@link NetworkType#NETWORK_4G } </li>
* <li>{@link NetworkType#NETWORK_3G } </li>
* <li>{@link NetworkType#NETWORK_2G } </li>
* <li>{@link NetworkType#NETWORK_UNKNOWN} </li>
* <li>{@link NetworkType#NETWORK_NO } </li>
* </ul>
*/
public static NetworkType getNetworkType() {
NetworkType netType = NetworkType.NETWORK_NO;
NetworkInfo info = getActiveNetworkInfo();
if (info != null && info.isAvailable()) {
if (info.getType() == ConnectivityManager.TYPE_WIFI) {
netType = NetworkType.NETWORK_WIFI;
} else if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
switch (info.getSubtype()) {
case NETWORK_TYPE_GSM:
case TelephonyManager.NETWORK_TYPE_GPRS:
case TelephonyManager.NETWORK_TYPE_CDMA:
case TelephonyManager.NETWORK_TYPE_EDGE:
case TelephonyManager.NETWORK_TYPE_1xRTT:
case TelephonyManager.NETWORK_TYPE_IDEN:
netType = NetworkType.NETWORK_2G;
break;
case NETWORK_TYPE_TD_SCDMA:
case TelephonyManager.NETWORK_TYPE_EVDO_A:
case TelephonyManager.NETWORK_TYPE_UMTS:
case TelephonyManager.NETWORK_TYPE_EVDO_0:
case TelephonyManager.NETWORK_TYPE_HSDPA:
case TelephonyManager.NETWORK_TYPE_HSUPA:
case TelephonyManager.NETWORK_TYPE_HSPA:
case TelephonyManager.NETWORK_TYPE_EVDO_B:
case TelephonyManager.NETWORK_TYPE_EHRPD:
case TelephonyManager.NETWORK_TYPE_HSPAP:
netType = NetworkType.NETWORK_3G;
break;
case NETWORK_TYPE_IWLAN:
case TelephonyManager.NETWORK_TYPE_LTE:
netType = NetworkType.NETWORK_4G;
break;
default:
String subtypeName = info.getSubtypeName();
if (subtypeName.equalsIgnoreCase("TD-SCDMA")
|| subtypeName.equalsIgnoreCase("WCDMA")
|| subtypeName.equalsIgnoreCase("CDMA2000")) {
netType = NetworkType.NETWORK_3G;
} else {
netType = NetworkType.NETWORK_UNKNOWN;
}
break;
}
} else {
netType = NetworkType.NETWORK_UNKNOWN;
}
}
return netType;
}
示例12: getNetworkType
/**
* 判断当前网络类型-1为未知网络0为没有网络连接1网络断开或关闭2为以太网3为WiFi4为2G5为3G6为4G
*/
public static int getNetworkType(Context context) {
ConnectivityManager connectMgr = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectMgr.getActiveNetworkInfo();
if (networkInfo == null) {
/** 没有任何网络 */
return 0;
}
if (!networkInfo.isConnected()) {
/** 网络断开或关闭 */
return 1;
}
if (networkInfo.getType() == ConnectivityManager.TYPE_ETHERNET) {
/** 以太网网络 */
return 2;
} else if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
/** wifi网络,当激活时,默认情况下,所有的数据流量将使用此连接 */
return 3;
} else if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
/** 移动数据连接,不能与连接共存,如果wifi打开,则自动关闭 */
switch (networkInfo.getSubtype()) {
case TelephonyManager.NETWORK_TYPE_GPRS:
case TelephonyManager.NETWORK_TYPE_EDGE:
case TelephonyManager.NETWORK_TYPE_CDMA:
case TelephonyManager.NETWORK_TYPE_1xRTT:
case TelephonyManager.NETWORK_TYPE_IDEN:
/** 2G网络 */
case TelephonyManager.NETWORK_TYPE_UMTS:
case TelephonyManager.NETWORK_TYPE_EVDO_0:
case TelephonyManager.NETWORK_TYPE_EVDO_A:
case TelephonyManager.NETWORK_TYPE_HSDPA:
case TelephonyManager.NETWORK_TYPE_HSUPA:
case TelephonyManager.NETWORK_TYPE_HSPA:
case TelephonyManager.NETWORK_TYPE_EVDO_B:
case TelephonyManager.NETWORK_TYPE_EHRPD:
case TelephonyManager.NETWORK_TYPE_HSPAP:
/** 3G网络 */
case TelephonyManager.NETWORK_TYPE_LTE:
/** 4G网络 */
return 4;
}
}
/** 未知网络 */
return -1;
}
示例13: isMobile
/**
* 检查是否是移动网络
*/
public static boolean isMobile(Context context) {
NetworkInfo info = getNetworkInfo(context);
if (info != null) {
if (info.getType() == ConnectivityManager.TYPE_MOBILE)
return true;
}
return false;
}
示例14: getNetWorkType
/**
* 获取当前网络状态
*
* @param context
* @return -1:无网络 1:wifi 0:移动网络
*/
public static int getNetWorkType(Context context) {
int mNetWorkType = NETWORK_NONE;
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = manager.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
int netType = networkInfo.getType();
if (netType == ConnectivityManager.TYPE_WIFI) {
mNetWorkType = NETWORK_WIFI;
} else if (netType == ConnectivityManager.TYPE_MOBILE) {
mNetWorkType = NETWORK_MOBILE;
}
}
return mNetWorkType;
}
示例15: isInternetEnabled
/**
* Checks if the internet is enabled
*
* @param context The application context instance
*
* @return The internet enabled status
*/
static boolean isInternetEnabled(Context context)
{
// Initializing the connectivity Manager
ConnectivityManager activeConnection = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
// Getting the network information
NetworkInfo networkInfo = activeConnection.getActiveNetworkInfo();
return networkInfo != null && (networkInfo.getType() == ConnectivityManager.TYPE_WIFI || networkInfo.getType() == ConnectivityManager.TYPE_MOBILE);
}