本文整理汇总了Java中android.net.NetworkInfo.getTypeName方法的典型用法代码示例。如果您正苦于以下问题:Java NetworkInfo.getTypeName方法的具体用法?Java NetworkInfo.getTypeName怎么用?Java NetworkInfo.getTypeName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.net.NetworkInfo
的用法示例。
在下文中一共展示了NetworkInfo.getTypeName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNetworkTypeName
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* Get network type name
*
* @param context
* @return
*/
public static String getNetworkTypeName(Context context) {
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo;
String type = NETWORK_TYPE_DISCONNECT;
if (manager == null || (networkInfo = manager.getActiveNetworkInfo()) == null) {
return type;
}
if (networkInfo.isConnected()) {
String typeName = networkInfo.getTypeName();
if ("WIFI".equalsIgnoreCase(typeName)) {
type = NETWORK_TYPE_WIFI;
} else if ("MOBILE".equalsIgnoreCase(typeName)) {
String proxyHost = android.net.Proxy.getDefaultHost();
type = TextUtils.isEmpty(proxyHost) ? (isFastMobileNetwork(context) ? NETWORK_TYPE_3G : NETWORK_TYPE_2G)
: NETWORK_TYPE_WAP;
} else {
type = NETWORK_TYPE_UNKNOWN;
}
}
return type;
}
示例2: isWifiConnectivityType
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* @brief Checks the connectivity type of the terminal
* @return True if the connectivity type is Wifi, false in another case.
* @details Checks the connectivity type of the terminal
*/
//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;
}
}
示例3: getNetworkTypeName
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* Get network type name
*
* @param context
* @return
*/
public static String getNetworkTypeName(Context context) {
ConnectivityManager manager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo;
String type = NETWORK_TYPE_DISCONNECT;
if (manager == null || (networkInfo = manager.getActiveNetworkInfo()) == null) {
return type;
}
if (networkInfo.isConnected()) {
String typeName = networkInfo.getTypeName();
if ("WIFI".equalsIgnoreCase(typeName)) {
type = NETWORK_TYPE_WIFI;
} else if ("MOBILE".equalsIgnoreCase(typeName)) {
String proxyHost = android.net.Proxy.getDefaultHost();
type = TextUtils.isEmpty(proxyHost) ? (isFastMobileNetwork(context) ? NETWORK_TYPE_3G : NETWORK_TYPE_2G)
: NETWORK_TYPE_WAP;
} else {
type = NETWORK_TYPE_UNKNOWN;
}
}
return type;
}
示例4: p
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static String p(Context context) {
try {
if (a(context, "android.permission.INTERNET") && a(context, "android.permission" +
".ACCESS_NETWORK_STATE")) {
NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService
("connectivity")).getActiveNetworkInfo();
if (activeNetworkInfo != null && activeNetworkInfo.isConnected()) {
String typeName = activeNetworkInfo.getTypeName();
String extraInfo = activeNetworkInfo.getExtraInfo();
if (typeName != null) {
return typeName.equalsIgnoreCase("WIFI") ? "WIFI" : typeName
.equalsIgnoreCase("MOBILE") ? extraInfo == null ? "MOBILE" :
extraInfo : extraInfo == null ? typeName : extraInfo;
}
}
return null;
}
f.e((Object) "can not get the permission of android.permission.ACCESS_WIFI_STATE");
return null;
} catch (Object th) {
f.e(th);
}
}
示例5: getNetworkConnectedType
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* 获取设备网络连接状态,并且包含网络类型:2G/(3G/4G)/WIFI
* 返回值:NETWORKTYPE_INVALID,NETWORKTYPE_WAP,NETWORKTYPE_2G,NETWORKTYPE_3G,NETWORKTYPE_WIFI
* @param context
* @return
*/
public static int getNetworkConnectedType(Context context) {
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = manager.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
String type = networkInfo.getTypeName();
if ("WIFI".equalsIgnoreCase(type)) {
return NETWORKTYPE_WIFI;
} else if ("MOBILE".equalsIgnoreCase(type)) {
String proxyHost = android.net.Proxy.getDefaultHost();
if (TextUtils.isEmpty(proxyHost)) {
return isFastMobileNetwork(context) ? NETWORKTYPE_3G : NETWORKTYPE_2G;
} else {
return NETWORKTYPE_WAP;
}
} else {
return NETWORKTYPE_INVALID;
}
} else {
return NETWORKTYPE_INVALID;
}
}
示例6: getNetworkTypeName
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* Get network type name
*
* @param context context
* @return Network type name
*/
public static String getNetworkTypeName(Context context) {
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo;
String type = NETWORK_TYPE_DISCONNECT;
if (manager == null || (networkInfo = manager.getActiveNetworkInfo()) == null) return type;
if (networkInfo.isConnected()) {
String typeName = networkInfo.getTypeName();
if ("WIFI".equalsIgnoreCase(typeName))
type = NETWORK_TYPE_WIFI;
else if ("MOBILE".equalsIgnoreCase(typeName))
type = TextUtils.isEmpty(android.net.Proxy.getDefaultHost()) ?
(isFastMobileNetwork(context) ? NETWORK_TYPE_3G : NETWORK_TYPE_2G) : NETWORK_TYPE_WAP;
else
type = NETWORK_TYPE_UNKNOWN;
}
return type;
}
示例7: getNetworkTypeName
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static String getNetworkTypeName(Context context) {
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo;
String type = NETWORK_TYPE_DISCONNECT;
if (manager == null || (networkInfo = manager.getActiveNetworkInfo()) == null) {
return type;
}
if (networkInfo.isConnected()) {
String typeName = networkInfo.getTypeName();
if ("WIFI".equalsIgnoreCase(typeName)) {
type = NETWORK_TYPE_WIFI;
} else if ("MOBILE".equalsIgnoreCase(typeName)) {
String proxyHost = android.net.Proxy.getDefaultHost();
type = TextUtils.isEmpty(proxyHost) ? (isFastMobileNetwork(context) ? NETWORK_TYPE_3G : NETWORK_TYPE_2G)
: NETWORK_TYPE_WAP;
} else {
type = NETWORK_TYPE_UNKNOWN;
}
}
return type;
}
示例8: getNetworkTypeName
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* Get network type name
*
* @param context
* @return
*/
public static String getNetworkTypeName(Context context) {
ConnectivityManager manager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo;
String type = NETWORK_TYPE_DISCONNECT;
if (manager == null || (networkInfo = manager.getActiveNetworkInfo()) == null) {
return type;
};
if (networkInfo.isConnected()) {
String typeName = networkInfo.getTypeName();
if ("WIFI".equalsIgnoreCase(typeName)) {
type = NETWORK_TYPE_WIFI;
} else if ("MOBILE".equalsIgnoreCase(typeName)) {
String proxyHost = android.net.Proxy.getDefaultHost();
type = TextUtils.isEmpty(proxyHost) ? (isFastMobileNetwork(context) ? NETWORK_TYPE_3G : NETWORK_TYPE_2G)
: NETWORK_TYPE_WAP;
} else {
type = NETWORK_TYPE_UNKNOWN;
}
}
return type;
}
示例9: getNetworkTypeName
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static String getNetworkTypeName(Context context) {
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo;
String type = NETWORK_TYPE_DISCONNECT;
if (manager == null || (networkInfo = manager.getActiveNetworkInfo()) == null) {
return type;
}
if (networkInfo.isConnected()) {
String typeName = networkInfo.getTypeName();
if ("WIFI".equalsIgnoreCase(typeName)) {
type = NETWORK_TYPE_WIFI;
} else if ("MOBILE".equalsIgnoreCase(typeName)) {
//String proxyHost = android.net.Proxy.getDefaultHost();//deprecated
String proxyHost = System.getProperty("http.proxyHost");
type = TextUtils.isEmpty(proxyHost) ? (isFastMobileNetwork(context) ? NETWORK_TYPE_3G : NETWORK_TYPE_2G) : NETWORK_TYPE_WAP;
} else {
type = NETWORK_TYPE_UNKNOWN;
}
}
return type;
}
示例10: getNetworkType
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static String getNetworkType(Context context) {
String networkType = EnvironmentCompat.MEDIA_UNKNOWN;
if (context == null) {
LOG.w(TAG, "get network type failed(null context)");
return networkType;
}
ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService("connectivity");
if (connMgr == null) {
LOG.e(TAG, "get connectivity manager failed");
return networkType;
}
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo == null) {
return networkType;
}
String typeName = networkInfo.getTypeName();
String subTypeName = networkInfo.getSubtypeName();
String extraInfo = networkInfo.getExtraInfo();
if (TextUtils.isEmpty(subTypeName)) {
networkType = typeName + "/" + extraInfo;
} else {
networkType = typeName + "(" + subTypeName + ")/" + extraInfo;
}
return networkType;
}
示例11: e
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static String e(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService
("connectivity");
if (connectivityManager == null) {
return "MOBILE";
}
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
if (activeNetworkInfo != null) {
return activeNetworkInfo.getTypeName();
}
return "MOBILE";
}
示例12: a
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static HttpHost a(Context context) {
if (context == null) {
return null;
}
try {
if (context.getPackageManager().checkPermission("android.permission" +
".ACCESS_NETWORK_STATE", context.getPackageName()) != 0) {
return null;
}
NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService
("connectivity")).getActiveNetworkInfo();
if (activeNetworkInfo == null) {
return null;
}
if (activeNetworkInfo.getTypeName() != null && activeNetworkInfo.getTypeName()
.equalsIgnoreCase("WIFI")) {
return null;
}
String extraInfo = activeNetworkInfo.getExtraInfo();
if (extraInfo == null) {
return null;
}
if (extraInfo.equals("cmwap") || extraInfo.equals("3gwap") || extraInfo.equals
("uniwap")) {
return new HttpHost(Network.CMWAP_GATEWAY, 80);
}
if (extraInfo.equals("ctwap")) {
return new HttpHost("10.0.0.200", 80);
}
return null;
} catch (Object th) {
f.e(th);
}
}
示例13: onReceive
import android.net.NetworkInfo; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
long time = System.currentTimeMillis();
if (time - oldTime < 1000) {
return;
}
oldTime = time;
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";
}
if (onNetListener != null) {
onNetListener.onNetStatus(netType, netName);
}
}
示例14: 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);
}
示例15: E
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static String E(Context context) {
String str = "";
try {
if (r.a(context, "android.permission.INTERNET") && r.a(context, "android.permission" +
".ACCESS_NETWORK_STATE")) {
String typeName;
NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService
("connectivity")).getActiveNetworkInfo();
if (activeNetworkInfo != null && activeNetworkInfo.isConnected()) {
typeName = activeNetworkInfo.getTypeName();
String extraInfo = activeNetworkInfo.getExtraInfo();
if (typeName != null) {
if (typeName.equalsIgnoreCase("WIFI")) {
return "WIFI";
}
if (typeName.equalsIgnoreCase("MOBILE")) {
return extraInfo != null ? extraInfo : "MOBILE";
} else {
if (extraInfo != null) {
return extraInfo;
}
return typeName;
}
}
}
typeName = str;
return typeName;
}
cT.d("can not get the permission of android.permission.ACCESS_WIFI_STATE");
return str;
} catch (Throwable th) {
cT.b(th);
return str;
}
}