本文整理汇总了Java中android.net.ConnectivityManager.TYPE_ETHERNET属性的典型用法代码示例。如果您正苦于以下问题:Java ConnectivityManager.TYPE_ETHERNET属性的具体用法?Java ConnectivityManager.TYPE_ETHERNET怎么用?Java ConnectivityManager.TYPE_ETHERNET使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.net.ConnectivityManager
的用法示例。
在下文中一共展示了ConnectivityManager.TYPE_ETHERNET属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onReceive
@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);
}
}
示例2: connectionTypeString
private String connectionTypeString(int connectionType) {
switch (connectionType) {
case ConnectivityManager.TYPE_WIFI:
return "Wifi";
case ConnectivityManager.TYPE_BLUETOOTH:
return "Bluetooth";
case ConnectivityManager.TYPE_ETHERNET:
return "Ethernet";
case ConnectivityManager.TYPE_MOBILE:
return "Mobile";
case ConnectivityManager.TYPE_MOBILE_DUN:
return "Mobile dun";
case ConnectivityManager.TYPE_VPN:
return "VPN";
default:
return "Unknown";
}
}
示例3: onReceive
public void onReceive(Context context, Intent intent) {
boolean noConnectivity = intent.getBooleanExtra(
ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
String reason = intent
.getStringExtra(ConnectivityManager.EXTRA_REASON);
boolean isFailover = intent.getBooleanExtra(
ConnectivityManager.EXTRA_IS_FAILOVER, false);
NetworkInfo currentNetworkInfo = (NetworkInfo) intent
.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
NetworkInfo otherNetworkInfo = (NetworkInfo) intent
.getParcelableExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO);
if (currentNetworkInfo.isConnected()
&& currentNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
tip.setText("Connected to the Wireless Network");
} else if (currentNetworkInfo.isConnected()
&& currentNetworkInfo.getType() == ConnectivityManager.TYPE_ETHERNET) {
tip.setText("Connected to the Wired Network");
}
}
示例4: getConnectivityStatus
/**
* Uses the provided context to determine the current connectivity status.
*
* @param context A context used to retrieve connection information from
* @return A non-null value defined in {@link Status}
*/
public static Status getConnectivityStatus(Context context) {
ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
switch (activeNetwork != null ? activeNetwork.getType() : CONST_NO_NETWORK) {
case ConnectivityManager.TYPE_WIFI:
case ConnectivityManager.TYPE_ETHERNET:
return Status.WIFI;
case ConnectivityManager.TYPE_MOBILE:
case ConnectivityManager.TYPE_BLUETOOTH:
case ConnectivityManager.TYPE_WIMAX:
return Status.MOBILE;
default:
return Status.NONE;
}
}
示例5: isLocalNetworkConnected
public static boolean isLocalNetworkConnected(Context context) {
// Check network status
boolean networkEnabled = false;
ConnectivityManager connectivity = (ConnectivityManager)(context.getSystemService(Context.CONNECTIVITY_SERVICE));
if (connectivity != null) {
NetworkInfo networkInfo = connectivity.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected() &&
(networkInfo.getType() == ConnectivityManager.TYPE_WIFI || networkInfo.getType() == ConnectivityManager.TYPE_ETHERNET)) {
networkEnabled = true;
}
}
return networkEnabled;
}
示例6: adjustThreadCount
void adjustThreadCount(NetworkInfo info) {
if (info == null || !info.isConnectedOrConnecting()) {
setThreadCount(DEFAULT_THREAD_COUNT);
return;
}
switch (info.getType()) {
case ConnectivityManager.TYPE_WIFI:
case ConnectivityManager.TYPE_WIMAX:
case ConnectivityManager.TYPE_ETHERNET:
setThreadCount(4);
break;
case ConnectivityManager.TYPE_MOBILE:
switch (info.getSubtype()) {
case TelephonyManager.NETWORK_TYPE_LTE: // 4G
case TelephonyManager.NETWORK_TYPE_HSPAP:
case TelephonyManager.NETWORK_TYPE_EHRPD:
setThreadCount(3);
break;
case TelephonyManager.NETWORK_TYPE_UMTS: // 3G
case TelephonyManager.NETWORK_TYPE_CDMA:
case TelephonyManager.NETWORK_TYPE_EVDO_0:
case TelephonyManager.NETWORK_TYPE_EVDO_A:
case TelephonyManager.NETWORK_TYPE_EVDO_B:
setThreadCount(2);
break;
case TelephonyManager.NETWORK_TYPE_GPRS: // 2G
case TelephonyManager.NETWORK_TYPE_EDGE:
setThreadCount(1);
break;
default:
setThreadCount(DEFAULT_THREAD_COUNT);
}
break;
default:
setThreadCount(DEFAULT_THREAD_COUNT);
}
}
示例7: getNetWorkType
/**
* 网络
*/
public static int getNetWorkType(Context context) {
int netType;
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;
break;
case ConnectivityManager.TYPE_WIFI:
netType = 1;
break;
case ConnectivityManager.TYPE_ETHERNET:
netType = 2;
break;
default:
netType = 3;
break;
}
} else {
netType = -1;
}
return netType;
}
示例8: isNetworkWiFi
/**
* Check if there is any connectivity to a WiFi network
*
* @param ctx the application Context
* @return true if the device is connected to WiFi
*/
public static boolean isNetworkWiFi(final Context ctx) {
final NetworkInfo info = getActiveNetworkInfo(ctx);
return info != null && (info.getType() == ConnectivityManager.TYPE_WIFI
|| info.getType() == ConnectivityManager.TYPE_ETHERNET);
}
示例9: checkNetworkType
static int checkNetworkType(Context context) {
int netType = 0;
//连接管理对象
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
//获取NetworkInfo对象
@SuppressLint("MissingPermission") NetworkInfo networkInfo = manager.getActiveNetworkInfo();
if (networkInfo == null)
return netType;
switch (networkInfo.getType()) {
case ConnectivityManager.TYPE_WIFI:
case ConnectivityManager.TYPE_WIMAX:
case ConnectivityManager.TYPE_ETHERNET:
return 1;
case ConnectivityManager.TYPE_MOBILE:
switch (networkInfo.getSubtype()) {
case TelephonyManager.NETWORK_TYPE_LTE: // 4G
case TelephonyManager.NETWORK_TYPE_HSPAP:
case TelephonyManager.NETWORK_TYPE_EHRPD:
return 2;
case TelephonyManager.NETWORK_TYPE_UMTS: // 3G
case TelephonyManager.NETWORK_TYPE_CDMA:
case TelephonyManager.NETWORK_TYPE_EVDO_0:
case TelephonyManager.NETWORK_TYPE_EVDO_A:
case TelephonyManager.NETWORK_TYPE_EVDO_B:
return 3;
case TelephonyManager.NETWORK_TYPE_GPRS: // 2G
case TelephonyManager.NETWORK_TYPE_EDGE:
return 4;
default:
return netType;
}
default:
return netType;
}
}
示例10: checkNetworkType
public static int checkNetworkType(Context context) {
int netType = 0;
//连接管理对象
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
//获取NetworkInfo对象
NetworkInfo networkInfo = manager.getActiveNetworkInfo();
if (networkInfo == null)
return netType;
switch (networkInfo.getType()) {
case ConnectivityManager.TYPE_WIFI:
case ConnectivityManager.TYPE_WIMAX:
case ConnectivityManager.TYPE_ETHERNET:
return 1;
case ConnectivityManager.TYPE_MOBILE:
switch (networkInfo.getSubtype()) {
case TelephonyManager.NETWORK_TYPE_LTE: // 4G
case TelephonyManager.NETWORK_TYPE_HSPAP:
case TelephonyManager.NETWORK_TYPE_EHRPD:
return 2;
case TelephonyManager.NETWORK_TYPE_UMTS: // 3G
case TelephonyManager.NETWORK_TYPE_CDMA:
case TelephonyManager.NETWORK_TYPE_EVDO_0:
case TelephonyManager.NETWORK_TYPE_EVDO_A:
case TelephonyManager.NETWORK_TYPE_EVDO_B:
return 3;
case TelephonyManager.NETWORK_TYPE_GPRS: // 2G
case TelephonyManager.NETWORK_TYPE_EDGE:
return 4;
default:
return netType;
}
default:
return netType;
}
}
示例11: isEthernetByType
/**
* 判断当前网络的类型是否是ETHERNET
*
* @param context 上下文
* @return 当前网络的类型是否是ETHERNET。false:当前没有网络连接或者网络类型不是ETHERNET
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
public static boolean isEthernetByType(Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) {
return false;
}
else {
return getCurrentNetworkType(context) ==
ConnectivityManager.TYPE_ETHERNET;
}
}
示例12: getNetworkTypeName
private static String getNetworkTypeName(int type) {
switch (type) {
case ConnectivityManager.TYPE_MOBILE:
return "MOBILE";
case ConnectivityManager.TYPE_WIFI:
return "WIFI";
case ConnectivityManager.TYPE_MOBILE_MMS:
return "MOBILE_MMS";
case ConnectivityManager.TYPE_MOBILE_SUPL:
return "MOBILE_SUPL";
case ConnectivityManager.TYPE_MOBILE_DUN:
return "MOBILE_DUN";
case ConnectivityManager.TYPE_MOBILE_HIPRI:
return "MOBILE_HIPRI";
case ConnectivityManager.TYPE_WIMAX:
return "WIMAX";
case ConnectivityManager.TYPE_BLUETOOTH:
return "BLUETOOTH";
case ConnectivityManager.TYPE_DUMMY:
return "DUMMY";
case ConnectivityManager.TYPE_ETHERNET:
return "ETHERNET";
case 10: // ConnectivityManager.TYPE_MOBILE_FOTA:
return "MOBILE_FOTA";
case 11: // ConnectivityManager.TYPE_MOBILE_IMS:
return "MOBILE_IMS";
case 12: // ConnectivityManager.TYPE_MOBILE_CBS:
return "MOBILE_CBS";
case 13: // ConnectivityManager.TYPE_WIFI_P2P:
return "WIFI_P2P";
default:
return Integer.toString(type);
}
}
示例13: getHdByNetwork
private
@Quality
int getHdByNetwork() {
ConnectivityManager cm = (ConnectivityManager) mContext.get().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
if (networkInfo == null || !networkInfo.isConnected()) {
LogUtil.e(TAG, "No networking found");
makeToast();
return VideoInfoImpl.HD_UNSPECIFIED;
}
switch (networkInfo.getType()) {
case ConnectivityManager.TYPE_WIFI:
case ConnectivityManager.TYPE_WIMAX:
case ConnectivityManager.TYPE_ETHERNET:
return HD_HIGH;
case ConnectivityManager.TYPE_MOBILE:
switch (networkInfo.getSubtype()) {
case TelephonyManager.NETWORK_TYPE_LTE:
case TelephonyManager.NETWORK_TYPE_HSPAP:
case TelephonyManager.NETWORK_TYPE_EHRPD:
return HD_STANDARD;
case TelephonyManager.NETWORK_TYPE_UMTS: // 3G
case TelephonyManager.NETWORK_TYPE_CDMA:
case TelephonyManager.NETWORK_TYPE_EVDO_0:
case TelephonyManager.NETWORK_TYPE_EVDO_A:
case TelephonyManager.NETWORK_TYPE_EVDO_B:
return HD_MEDIUM;
case TelephonyManager.NETWORK_TYPE_GPRS: // 2G
case TelephonyManager.NETWORK_TYPE_EDGE:
return HD_LOW;
default:
return HD_LOW;
}
default:
return HD_LOW;
}
}
示例14: updateNetworkType
/**
* Updates the network type based upon the type and subtype returned from
* the connectivity manager. Subtype is only used for cellular signals.
*
* @param type
* @param subType
*/
private void updateNetworkType(int type, int subType) {
switch (type) {
case ConnectivityManager.TYPE_WIFI:
case ConnectivityManager.TYPE_ETHERNET:
case ConnectivityManager.TYPE_BLUETOOTH:
mIsCellularConnection = false;
mIsAtLeast3G = false;
mIsAtLeast4G = false;
break;
case ConnectivityManager.TYPE_WIMAX:
mIsCellularConnection = true;
mIsAtLeast3G = true;
mIsAtLeast4G = true;
break;
case ConnectivityManager.TYPE_MOBILE:
mIsCellularConnection = true;
switch (subType) {
case TelephonyManager.NETWORK_TYPE_1xRTT:
case TelephonyManager.NETWORK_TYPE_CDMA:
case TelephonyManager.NETWORK_TYPE_EDGE:
case TelephonyManager.NETWORK_TYPE_GPRS:
case TelephonyManager.NETWORK_TYPE_IDEN:
mIsAtLeast3G = false;
mIsAtLeast4G = false;
break;
case TelephonyManager.NETWORK_TYPE_HSDPA:
case TelephonyManager.NETWORK_TYPE_HSUPA:
case TelephonyManager.NETWORK_TYPE_HSPA:
case TelephonyManager.NETWORK_TYPE_EVDO_0:
case TelephonyManager.NETWORK_TYPE_EVDO_A:
case TelephonyManager.NETWORK_TYPE_UMTS:
mIsAtLeast3G = true;
mIsAtLeast4G = false;
break;
case TelephonyManager.NETWORK_TYPE_LTE: // 4G
case TelephonyManager.NETWORK_TYPE_EHRPD: // 3G ++ interop
// with 4G
case TelephonyManager.NETWORK_TYPE_HSPAP: // 3G ++ but
// marketed as
// 4G
mIsAtLeast3G = true;
mIsAtLeast4G = true;
break;
default:
mIsCellularConnection = false;
mIsAtLeast3G = false;
mIsAtLeast4G = false;
}
}
}
示例15: updateNetworkType
/**
* Updates the network type based upon the type and subtype returned from
* the connectivity manager. Subtype is only used for cellular signals.
*
* @param type
* @param subType
*/
private void updateNetworkType(int type, int subType) {
switch (type) {
case ConnectivityManager.TYPE_WIFI:
case ConnectivityManager.TYPE_ETHERNET:
case ConnectivityManager.TYPE_BLUETOOTH:
mIsCellularConnection = false;
mIsAtLeast3G = false;
mIsAtLeast4G = false;
break;
case ConnectivityManager.TYPE_WIMAX:
mIsCellularConnection = true;
mIsAtLeast3G = true;
mIsAtLeast4G = true;
break;
case ConnectivityManager.TYPE_MOBILE:
mIsCellularConnection = true;
switch (subType) {
case TelephonyManager.NETWORK_TYPE_1xRTT:
case TelephonyManager.NETWORK_TYPE_CDMA:
case TelephonyManager.NETWORK_TYPE_EDGE:
case TelephonyManager.NETWORK_TYPE_GPRS:
case TelephonyManager.NETWORK_TYPE_IDEN:
mIsAtLeast3G = false;
mIsAtLeast4G = false;
break;
case TelephonyManager.NETWORK_TYPE_HSDPA:
case TelephonyManager.NETWORK_TYPE_HSUPA:
case TelephonyManager.NETWORK_TYPE_HSPA:
case TelephonyManager.NETWORK_TYPE_EVDO_0:
case TelephonyManager.NETWORK_TYPE_EVDO_A:
case TelephonyManager.NETWORK_TYPE_UMTS:
mIsAtLeast3G = true;
mIsAtLeast4G = false;
break;
case TelephonyManager.NETWORK_TYPE_LTE: // 4G
case TelephonyManager.NETWORK_TYPE_EHRPD: // 3G ++ interop
// with 4G
case TelephonyManager.NETWORK_TYPE_HSPAP: // 3G ++ but
// marketed as
// 4G
mIsAtLeast3G = true;
mIsAtLeast4G = true;
break;
default:
mIsCellularConnection = false;
mIsAtLeast3G = false;
mIsAtLeast4G = false;
}
}
}