本文整理汇总了Java中android.net.NetworkInfo.getSubtypeName方法的典型用法代码示例。如果您正苦于以下问题:Java NetworkInfo.getSubtypeName方法的具体用法?Java NetworkInfo.getSubtypeName怎么用?Java NetworkInfo.getSubtypeName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.net.NetworkInfo
的用法示例。
在下文中一共展示了NetworkInfo.getSubtypeName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getActiveNetworkLabel
import android.net.NetworkInfo; //导入方法依赖的package包/类
public String getActiveNetworkLabel() {
if (this.sAppContext == null) {
return EnvironmentCompat.MEDIA_UNKNOWN;
}
try {
ConnectivityManager connectivityManager = (ConnectivityManager) this.sAppContext
.getSystemService("connectivity");
if (connectivityManager == null) {
return EnvironmentCompat.MEDIA_UNKNOWN;
}
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
if (activeNetworkInfo == null) {
return EnvironmentCompat.MEDIA_UNKNOWN;
}
if (activeNetworkInfo.getType() != 1) {
return activeNetworkInfo.getTypeName() + SocializeConstants.OP_DIVIDER_MINUS +
activeNetworkInfo.getSubtypeName();
}
WifiManager wifiManager = (WifiManager) this.sAppContext.getSystemService("wifi");
if (!(wifiManager == null || wifiManager.getConnectionInfo() == null)) {
return "WIFI-" + wifiManager.getConnectionInfo().getSSID();
}
return EnvironmentCompat.MEDIA_UNKNOWN;
} catch (Exception e) {
}
}
示例2: getNetworkAccessMode
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static String[] getNetworkAccessMode(Context context) {
String[] strArr = new String[]{UNKNOW, UNKNOW};
if (context.getPackageManager().checkPermission("android.permission" +
".ACCESS_NETWORK_STATE", context.getPackageName()) != 0) {
strArr[0] = UNKNOW;
return strArr;
}
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService
("connectivity");
if (connectivityManager == null) {
strArr[0] = UNKNOW;
return strArr;
} else if (connectivityManager.getNetworkInfo(1).getState() == State.CONNECTED) {
strArr[0] = "Wi-Fi";
return strArr;
} else {
NetworkInfo networkInfo = connectivityManager.getNetworkInfo(0);
if (networkInfo.getState() != State.CONNECTED) {
return strArr;
}
strArr[0] = "2G/3G";
strArr[1] = networkInfo.getSubtypeName();
return strArr;
}
}
示例3: getNetWorkType
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* 网络
*/
public static void getNetWorkType(Context context, OnNetStatusListener listener) {
int netType;
String netName;
ConnectivityManager mConnectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = mConnectivityManager.getActiveNetworkInfo();
if (netInfo != null && netInfo.isAvailable()) {
switch (netInfo.getType()) {
case ConnectivityManager.TYPE_MOBILE:
netType = 0;
netName = netInfo.getSubtypeName();
break;
case ConnectivityManager.TYPE_WIFI:
netType = 1;
netName = netInfo.getTypeName();
break;
case ConnectivityManager.TYPE_ETHERNET:
netType = 2;
netName = netInfo.getTypeName();
break;
default:
netType = 3;
netName = "OtherNetWork";
break;
}
} else {
netType = -1;
netName = "NoNetWork";
}
listener.onNetStatus(netType, netName);
}
示例4: j
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static String[] j(Context context) {
String[] strArr = new String[]{"", ""};
try {
if (context.getPackageManager().checkPermission("android.permission.ACCESS_NETWORK_STATE", context.getPackageName()) != 0) {
strArr[0] = "";
return strArr;
}
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
if (connectivityManager == null) {
strArr[0] = "";
return strArr;
} else if (connectivityManager.getNetworkInfo(1).getState() == State.CONNECTED) {
strArr[0] = d;
return strArr;
} else {
NetworkInfo networkInfo = connectivityManager.getNetworkInfo(0);
if (networkInfo.getState() == State.CONNECTED) {
strArr[0] = c;
strArr[1] = networkInfo.getSubtypeName();
return strArr;
}
return strArr;
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例5: c
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static String c(Context context) {
try {
NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService(z[45])).getActiveNetworkInfo();
if (activeNetworkInfo == null) {
return z[62];
}
String typeName = activeNetworkInfo.getTypeName();
String subtypeName = activeNetworkInfo.getSubtypeName();
return typeName == null ? z[62] : subtypeName != null ? typeName + "," + subtypeName : typeName;
} catch (Exception e) {
e.printStackTrace();
return z[62];
}
}
示例6: getNetTypeName
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* 获取网络类型
*/
public static String getNetTypeName(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivityManager != null) {
NetworkInfo activeNetworkInfo = connectivityManager
.getActiveNetworkInfo();
if (activeNetworkInfo == null) {
return "NoNet";
}
if (activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
return activeNetworkInfo.getTypeName();
} else {
String typeName = activeNetworkInfo.getSubtypeName();
//Log.i("网络名称:", typeName);
if (typeName == null || typeName.length() == 0) {
return "Unknown";
} else if (typeName.length() > 3) {
return activeNetworkInfo.getSubtypeName().substring(0, 4);
} else {
return activeNetworkInfo.getSubtypeName().substring(0, typeName.length());
}
}
} else {
return "NoNet";
}
}
示例7: getNetWorkType
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* 获取当前的网络类型(WIFI,2G,3G,4G)
* <p>需添加权限 {@code <uses-permission android:name="android.permission
* .ACCESS_NETWORK_STATE"/>}</p>
*
* @param context 上下文
* @return 网络类型
* <ul>
* <li>{@link #NETWORK_WIFI } = 1;</li>
* <li>{@link #NETWORK_4G } = 4;</li>
* <li>{@link #NETWORK_3G } = 3;</li>
* <li>{@link #NETWORK_2G } = 2;</li>
* <li>{@link #NETWORK_UNKNOWN} = 5;</li>
* <li>{@link #NETWORK_NO } = -1;</li>
* </ul>
*/
public static int getNetWorkType(Context context) {
int netType = NETWORK_NO;
NetworkInfo info = getActiveNetworkInfo(context);
if (info != null && info.isAvailable()) {
if (info.getType() == ConnectivityManager.TYPE_WIFI) {
netType = 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 = 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 = NETWORK_3G;
break;
case NETWORK_TYPE_IWLAN:
case TelephonyManager.NETWORK_TYPE_LTE:
netType = NETWORK_4G;
break;
default:
String subtypeName = info.getSubtypeName();
if (subtypeName.equalsIgnoreCase("TD-SCDMA")
|| subtypeName.equalsIgnoreCase("WCDMA")
|| subtypeName.equalsIgnoreCase("CDMA2000")) {
netType = NETWORK_3G;
} else {
netType = NETWORK_UNKNOWN;
}
break;
}
} else {
netType = NETWORK_UNKNOWN;
}
}
return netType;
}
示例8: getNetworkType
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* 获取当前网络类型
* <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>}</p>
*
* @return 网络类型
* <ul>
* <li>{@link NetworkUtils.NetworkType#NETWORK_WIFI } </li>
* <li>{@link NetworkUtils.NetworkType#NETWORK_4G } </li>
* <li>{@link NetworkUtils.NetworkType#NETWORK_3G } </li>
* <li>{@link NetworkUtils.NetworkType#NETWORK_2G } </li>
* <li>{@link NetworkUtils.NetworkType#NETWORK_UNKNOWN} </li>
* <li>{@link NetworkUtils.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;
}
示例9: getNetworkType
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* 获取当前网络类型
* <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;
}
示例10: getNetworkType
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* @return netType 返回类型
* @throws
* @方法名: getAPNType
* @说 明: 获取当前的网络状态 -1:没有网络 1:WIFI网络2:wap 网络3:net网络
* @参 数: @param context
* @参 数: @return
*/
public static NetType getNetworkType(Context context) {
NetType netType = null;
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = manager.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
netType = NetType.NETWORK_WIFI;
} else if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
// TD-SCDMA networkType is 17
int networkType = networkInfo.getSubtype();
switch (networkType) {
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: //api<8 : replace by 11
netType = NetType.NETWORK_2_G;
break;
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: //api<9 : replace by 14
case TelephonyManager.NETWORK_TYPE_EHRPD: //api<11 : replace by 12
case TelephonyManager.NETWORK_TYPE_HSPAP: //api<13 : replace by 15
netType = NetType.NETWORK_3_G;
break;
case TelephonyManager.NETWORK_TYPE_LTE: //api<11 : replace by 13
netType = NetType.NETWORK_4_G;
break;
default:
String typeName = networkInfo.getSubtypeName();
// http://baike.baidu.com/item/TD-SCDMA 中国移动 联通 电信 三种3G制式
if (typeName.equalsIgnoreCase("TD-SCDMA") || typeName.equalsIgnoreCase("WCDMA") || typeName.equalsIgnoreCase("CDMA2000")) {
netType = NetType.NETWORK_3_G;
} else {
netType = NetType.NETWORK_UNKNOWN;
}
break;
}
}
}
return netType;
}
示例11: getNetworkType
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* 获取当前网络类型
* <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>}</p>
*
* @return 网络类型
* <ul>
* <li>{@link XNetworkUtils.NetworkType#NETWORK_WIFI } </li>
* <li>{@link XNetworkUtils.NetworkType#NETWORK_4G } </li>
* <li>{@link XNetworkUtils.NetworkType#NETWORK_3G } </li>
* <li>{@link XNetworkUtils.NetworkType#NETWORK_2G } </li>
* <li>{@link XNetworkUtils.NetworkType#NETWORK_UNKNOWN} </li>
* <li>{@link XNetworkUtils.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: networkStateChange
import android.net.NetworkInfo; //导入方法依赖的package包/类
public void networkStateChange(Context context) {
NetworkInfo networkInfo = getCurrentNetworkInfo(context);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean sendusr1 = prefs.getBoolean("netchangereconnect", true);
String netstatestring;
if (networkInfo == null) {
netstatestring = "not connected";
} else {
String subtype = networkInfo.getSubtypeName();
if (subtype == null) subtype = "";
String extrainfo = networkInfo.getExtraInfo();
if (extrainfo == null) extrainfo = "";
/*
if(networkInfo.getType()==android.net.ConnectivityManager.TYPE_WIFI) {
WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiinfo = wifiMgr.getConnectionInfo();
extrainfo+=wifiinfo.getBSSID();
subtype += wifiinfo.getNetworkId();
}*/
netstatestring = String.format("%2$s %4$s to %1$s %3$s", networkInfo.getTypeName(), networkInfo.getDetailedState(), extrainfo, subtype);
}
if (networkInfo != null && networkInfo.getState() == State.CONNECTED) {
int newnet = networkInfo.getType();
boolean pendingDisconnect = (network == connectState.PENDINGDISCONNECT);
network = connectState.SHOULDBECONNECTED;
boolean sameNetwork;
if (lastConnectedNetwork == null || lastConnectedNetwork.getType() != networkInfo.getType() || !equalsObj(lastConnectedNetwork.getExtraInfo(), networkInfo.getExtraInfo()))
sameNetwork = false;
else sameNetwork = true;
/* Same network, connection still 'established' */
if (pendingDisconnect && sameNetwork) {
mDisconnectHandler.removeCallbacks(mDelayDisconnectRunnable);
// Reprotect the sockets just be sure
mManagement.networkChange(true);
} else {
/* Different network or connection not established anymore */
if (screen == connectState.PENDINGDISCONNECT) screen = connectState.DISCONNECTED;
if (shouldBeConnected()) {
mDisconnectHandler.removeCallbacks(mDelayDisconnectRunnable);
if (pendingDisconnect || !sameNetwork) mManagement.networkChange(sameNetwork);
else mManagement.resume();
}
lastNetwork = newnet;
lastConnectedNetwork = networkInfo;
}
} else if (networkInfo == null) {
// Not connected, stop openvpn, set last connected network to no network
lastNetwork = -1;
if (sendusr1) {
network = connectState.PENDINGDISCONNECT;
mDisconnectHandler.postDelayed(mDelayDisconnectRunnable, DISCONNECT_WAIT * 1000);
}
}
if (!netstatestring.equals(lastStateMsg)) VpnStatus.logInfo(R.string.netstatus, netstatestring);
lastStateMsg = netstatestring;
}
示例13: detectNetwork
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static void detectNetwork(Context context) {
try {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
NetworkInfo networkInfo = connectivityManager != null ? connectivityManager.getActiveNetworkInfo() : null;
String networkName = NETWORK_NAME_NO_NETWORK;
if (networkInfo != null && networkInfo.isAvailable()) {
networkName = networkInfo.getTypeName();
switch (networkInfo.getType()) {
case 0:
networkName = networkInfo.getSubtypeName();
switch (networkInfo.getSubtype()) {
case 1:
case 2:
case 4:
case 7:
case 11:
sNetworkType = 4;
sNetworkName = NETWORK_NAME_2G;
break;
case 3:
case 5:
case 6:
case 8:
case 9:
case 10:
case 12:
case 14:
case 15:
sNetworkType = 5;
sNetworkName = NETWORK_NAME_3G;
break;
case 13:
sNetworkType = 6;
sNetworkName = NETWORK_NAME_4G;
break;
default:
if (!NETWORK_NAME_TD_SCDMA.equalsIgnoreCase(networkName) && !NETWORK_NAME_WCDMA.equalsIgnoreCase(networkName) && !NETWORK_NAME_CDMA2000.equalsIgnoreCase(networkName)) {
sNetworkType = 2;
sNetworkName = NETWORK_NAME_MOBILE;
break;
}
sNetworkType = 5;
sNetworkName = NETWORK_NAME_3G;
break;
break;
}
case 1:
sNetworkType = 3;
sNetworkName = NETWORK_NAME_WIFI;
break;
case 9:
sNetworkType = 1;
sNetworkName = NETWORK_NAME_ETHERNET;
break;
default:
if (!NETWORK_NAME_PPPOE.equalsIgnoreCase(networkName)) {
sNetworkType = 8;
sNetworkName = NETWORK_NAME_MORE;
break;
}
sNetworkType = 1;
sNetworkName = NETWORK_NAME_ETHERNET;
break;
}
}
sNetworkType = 0;
sNetworkName = NETWORK_NAME_NO_NETWORK;
LogTool.i(TAG, "detectNetwork. network name(%s), network type(%s), ip(%s)", networkName, Integer.valueOf(sNetworkType), getIP());
} catch (Exception e) {
LogTool.e(TAG, "detectNetwork. " + e.toString());
sNetworkType = -1;
sNetworkName = NETWORK_NAME_NO_PERMISSION;
LogTool.i(TAG, "detectNetwork. network name(%s), network type(%s), ip(%s)", sNetworkName, Integer.valueOf(sNetworkType), getIP());
}
}
示例14: getNetworkType
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static NetworkType getNetworkType(NetworkInfo info) {
NetworkType netType = NetworkType.NETWORK_NO;
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;
}
示例15: getNetworkType
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* 获取网络状态,wifi,wap,2g,3g,4g.
*
* @return int 网络状态 {@link #NETWORK_TYPE_2G},{@link #NETWORK_TYPE_3G},{@link #NETWORK_TYPE_4G}
* {@link #NETWORK_TYPE_INVALID},{@link #NETWORK_TYPE_WAP},
* {@link #NETWORK_TYPE_WIFI}
*/
public static int getNetworkType() {
int strNetworkType = NETWORK_TYPE_INVALID;
NetworkInfo networkInfo = ((ConnectivityManager) UtilManager.getContext().getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
strNetworkType = NETWORK_TYPE_WIFI;
} else if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
String _strSubTypeName = networkInfo.getSubtypeName();
// TD-SCDMA networkType is 17
int networkType = networkInfo.getSubtype();
switch (networkType) {
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: //api<8 : replace by 11
strNetworkType = NETWORK_TYPE_2G;
break;
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: //api<9 : replace by 14
case TelephonyManager.NETWORK_TYPE_EHRPD: //api<11 : replace by 12
case TelephonyManager.NETWORK_TYPE_HSPAP: //api<13 : replace by 15
strNetworkType = NETWORK_TYPE_3G;
break;
case TelephonyManager.NETWORK_TYPE_LTE: //api<11 : replace by 13
strNetworkType = NETWORK_TYPE_4G;
break;
default:
// http://baike.baidu.com/item/TD-SCDMA 中国移动 联通 电信 三种3G制式
if (_strSubTypeName.equalsIgnoreCase("TD-SCDMA") || _strSubTypeName.equalsIgnoreCase("WCDMA") || _strSubTypeName.equalsIgnoreCase("CDMA2000")) {
strNetworkType = NETWORK_TYPE_3G;
} else {
strNetworkType = NETWORK_TYPE_UNKNOWN;
}
break;
}
}
}
return strNetworkType;
}