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;
}

你可能感兴趣的:(网络,andriod,linux系统)