Android下,判断网线是否插入的方法

1.通过调用命令:cat /sys/class/net/eth0/carrier

2.通过代码:

private boolean haveInternet()
{
	boolean result = false;
	ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); 
	NetworkInfo info=connManager.getActiveNetworkInfo();
	if (info == null || !info.isConnected())
	{
		result = false;
	}
	else 
	{
		if (!info.isAvailable())
		{
			result =false;
		}
		else
		{
			result = true;
		}
	}
	
	return result;
}

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页